How to checkout shared library pipeline other then master

半城伤御伤魂 提交于 2019-12-11 18:45:11

问题


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

回答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'
      }
    }
  }
}


来源:https://stackoverflow.com/questions/59202628/how-to-checkout-shared-library-pipeline-other-then-master

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!