Jenkins:当一个分支发生更改时触发构建,但在另一个分支中触发脚本



我有一个Jenkins管道作业,当更改被推送到Git存储库时会触发:

pipelineJob('MyJob') {
definition {
cpsScm {
scm {
git {
remote {
url('git@bitbucket.org:myorg/myproject.git')
credentials('jenkins-bitbucket')
}
branch('develop')
branch('master')
branch('release/*')
branch('hotfix/*')
}
}
}
}
properties {
triggers{
bitbucketTriggers {
repositoryPushAction(false,false,'develop')
}
}
disableConcurrentBuilds()
}
}

当作业触发时,我想运行一个位于不同Git存储库中的groovy脚本。这可能吗?

是的,有两种解决方案,

  1. 共享库-url
  2. 这种方法更加定制化。您可以创建自己的Java库并导出为customlib.jar文件。确保Java类路径附加您创建的customlib.jar文件。然后,您可以像import-customlib.classname一样直接在JenkinsFile中访问代码*

祝你好运!

最新更新