如何检出除主库以外的共享库管道 [英] How to checkout shared library pipeline other then master

查看:303
本文介绍了如何检出除主库以外的共享库管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Jenkins管理员没有执行者,并且由于我们公司拥有的Jenkins的设计而无法执行.我们有2个工作节点.当我添加Pipeline共享库时,默认情况下,Jenkins尝试在master中检出,由于明显的原因而失败,因为它找不到git,因为它在Jenkins master中不可用.

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

我不明白为什么Jenkins甚至可以尝试检出master中的共享库,因为master甚至没有执行者.

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

我查看了其他人的意见,但我的事情止于试图结账的地步.我该如何克服?我以为将共享库的Groovy文件保存在同一回购中,并将该库导入JenkinsFile,但似乎对我也不起作用.我尝试了,但詹金斯无法识别modules

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"

我尝试了libraryResource ('vars/sendNotifications.groovy'),但是它不起作用.詹金斯只是失败而没有抛出任何错误.

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

我认为但不知道如何实现的解决方案:

  1. 应该运行我的工作的节点中的Checkout管道库
  2. 忽略管道库,并在同一存储库中创建一个Groovy文件,然后将其导入JenkinsFile中.

推荐答案

您可以先尝试获取一个工作程序,然后从以下位置加载库:

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

这篇关于如何检出除主库以外的共享库管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆