0

My Jenkins master doesn't have an executor and it can't have due to the design of Jenkins we have in our company. We have 2 worker node. When I add Pipeline shared library then by default Jenkins tries to checkout in master and fails due to obvious reasons as it can't find git as it is not available in Jenkins master.

Cloning repository git@github.com:Test/jenkins-pipeline-shared.git


> git init /var/lib/jenkins/workspace/rp-pipe_PR-675@libs/slackNotify # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /var/lib/jenkins/workspace/rp-pipe_PR-675@libs/slackNotify

I don't understand why Jenkins can even try to checkout shared library in master because master doesn't even have an executor.

I looked at other people's opinion but my things stop at the point it tries to checkout. How can I get over this? I thought to keep my shared library groovy file in the same repo and import the library into JenkinsFile but seems like it is also not working for me. I tried this but Jenkins couldn't identify modules

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 14: Expected a step @ line 14, column 17.
modules.sendNotifications = load "vars/sendNotifications.groovy"

I tried libraryResource ('vars/sendNotifications.groovy') but it's not working. Jenkins just fails without throwing any error.

Solution which I think but don't know how to implement :

  1. Checkout pipeline library in the node where my job is suppose to run
  2. Ignore pipeline library and create a groovy file in the same repo and import that in the JenkinsFile
Psdet
  • 659
  • 9
  • 24
  • The shared library will be checked out to your workspace depending upon your usage. If your workspace is on a worker node, then it will exist there. – Matthew Schuchard Dec 05 '19 at 21:03
  • I manage my node from the JenkinsFile. the checkout happens before it hits the `agent { label '!master' }` in the pipeline. – Psdet Dec 05 '19 at 21:09

1 Answers1

1

You could try to acquire a worker first and then load the library from within:

pipeline {
  agent any
  stages {
    stage('Init') {
      steps {
        library 'my-fancy-library'
      }
    }
  }
}
Christopher
  • 1,103
  • 1
  • 6
  • 18
  • Now, I can see the checkout has been done in the worker node. Thanks but Still I get the same error - `Caused by: java.io.IOException: Cannot run program "git" (in directory "/var/lib/jenkins/workspace/rp-pipe_PR-675@libs/slackNotify"): error=2, No such file or directory`. I checked `which git` and I have git in the `PATH`. I don't know why it still complains – Psdet Dec 06 '19 at 15:53
  • I noticed that the Jenkins attempts to checkout the library repo in `var/lib/` and which ofcourse it doesn't have a permission to do that. Why it doesn't attempt to clone the repo in the `/home/ec2-user/workspace` like other repo? – Psdet Dec 06 '19 at 17:37
  • I think this is the workspace where your Jenkins runs. – Christopher Dec 13 '19 at 08:42
  • Accepting the answer as indeed it solved my original question of checking out to a worker node. – Psdet Dec 23 '19 at 15:06
  • yes, `/var/lib/` is the installation location but the workspace is `/home/ec2-user/workspace` and would expect git checkout over here as other that the shared library the git checkout is done in this directory. – Psdet Dec 23 '19 at 15:09