Kal*_*ari 5 git bitbucket polling jenkins jenkins-pipeline
我想使用两个 Git 存储库构建一个项目。其中一个包含源代码,而另一个包含构建和部署脚本。
我正在使用 Jenkins 管道来构建我的项目。管道脚本位于Jenkins-pipeline存储库中,源代码位于中间件存储库中。由于我的管道脚本位于 Jenkins-pipeline 存储库中,我正在使用 Jenkins-pipeline 存储库中的 Jenkinsfile 配置我的管道。
这是我正在使用的 Jenkins 文件:
pipeline {
agent any
parameters {
string(name: 'repo_branch', defaultValue: 'development', description: 'The branch to be checked out')
string(name: 'git_repo', defaultValue: 'ssh://git@my-server.com/middleware.git' description: 'Git repository from where we are going to checkout the code')
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
disableConcurrentBuilds()
timeout(time: 10, unit: 'MINUTES')
}
triggers {
pollSCM('* * * * *')
}
stages {
stage('Checkout git repo') {
steps {
git branch: "${params.repo_branch}", url: "${params.git_repo}", credentialsId: 'git-credentials'
}
}
stage('Build binary') {
steps {
sh "./gradlew clean build -x test"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,正如我们所看到的,我在 Jenkinsfile 中克隆的存储库是不同的,并且我保存 jenkinsfile 的存储库也是不同的。
现在的问题是:
在 Jenkins 文件中,每当存储库中有新提交时,我都会使用pollScm 触发我的 Jenkins 作业,但我有两个为该作业配置的存储库,因此
因此,每当这些存储库中有提交时,我的 Jenkins 工作就会被触发,这是我不希望的!我只想在源代码存储库中有新提交时触发我的 Jenkins 构建,并且在 Jenkins 管道存储库中有提交时不应触发构建。我怎么做?
我在 Jenkinsfile 中使用共享库,这些库也在另一个存储库中。当我在共享库存储库中提交某些内容时,Jenkins 作业也会被触发,并且我在多个作业中使用共享库,因此所有作业都会被触发,这是我不希望的。
PS 我无法使用 webhooks 来触发我的 Jenkins 构建,因为我的 Jenkins 位于专用网络中!
对于不包含在更改检查中的库,请取消选中相关库的“系统配置”页面中的“在作业最近更改中包含@Library更改”复选框,或在中设置新的可能参数“changelog = false”管道“@Library”指令。
对于管道本身不包含在“拉式供应链管理”中来说,这有点棘手。一种选择是将 Jenkinsfile 包含在代码存储库中,但如果 Jenkinsfile 本身发生更改,也会触发构建,但实际上并不需要。
另一种选择是在管道的启动中检查触发作业的更改是否在源存储库中或在管道存储库中,如果不在源存储库中,则停止构建。
| 归档时间: |
|
| 查看次数: |
4562 次 |
| 最近记录: |