我现在有一个基于 Jenkinsfile 的管道,其中包含多个阶段,每次提交到 Github 时都会由 webhook 触发。我想在每次提交时保持“构建”和“单元测试”阶段运行,但仅在分支准备拉取请求时运行“集成测试”阶段。
我想要的是:
stage("build)"{
// runs every commit
}
stage("unit tests"){
// runs every commit
}
stage("integration tests"){
// runs ONLY on pull request
}
Run Code Online (Sandbox Code Playgroud)
我一直无法找到解决方案,有什么想法吗?
小智 5
我找到了非常简单的声明式管道方法,无需任何插件,并且可以在任何地方使用。
stage (' PR check ') {
when {
branch 'PR-*'
}
steps {
sh '''
echo "PULL REQUEST CHECK IS DONE HERE"
'''
}
}
Run Code Online (Sandbox Code Playgroud)
在 #jenkins IRC 频道询问后,我得到了正确的方向。这可以使用https://wiki.jenkins.io/display/JENKINS/SCM+Filter+Branch+PR+Plugin实现
脚本化管道:
if(env.CHANGE_ID) {
// do something because it's a pull request
} else {
// not a pull request
}
Run Code Online (Sandbox Code Playgroud)
声明式管道:
pipeline {
stages {
stage('Example Deploy') {
when {
allOf {
environment name: 'CHANGE_ID', value: ''
branch 'master'
}
}
steps {
// not a pull request so do something
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
9541 次 |
| 最近记录: |