jenkins - Jenkins 使用构建触发器时
问题描述
我在我的 jenkins 中有一个多分支的工作,我有一个从我的 github 到我的 jenkins 的 webhook 设置,用于发送每个拉取请求更改并发布评论。
我要做的是让 github 发送拉取请求更改以用于索引目的,但不要运行该作业,除非开发人员在 github 拉取请求的评论中添加评论“测试”。
这是我Jenkinsfile
的
pipeline {
agent { label 'mac' }
stages {
stage ('Check Build Cause') {
steps {
script {
def cause = currentBuild.buildCauses.shortDescription
echo "${cause}"
}
}
}
stage ('Test') {
when {
expression {
currentBuild.buildCauses.shortDescription == "[GitHub pull request comment]"
}
}
steps {
sh 'bundle exec fastlane test'
}
}
}
}
所以我想如果触发器不是GitHub pull request comment
,不要运行任何东西。我已经尝试过了,但它不起作用。我已经尝试了 printcurrentBuild.buildCauses.shortDescription
变量并且它可以打印[GitHub pull request comment]
,但是我的作业仍然无法运行when expression
我怎样才能做到这一点?谢谢
解决方案
所以实际上问题是因为currentBuild.buildCauses.shortDescription
返回 ArrayList 而不是纯字符串。
我真的不认为这是一个数组[GitHub pull request comment]
,所以我设法只用数组索引解决了这个问题。
currentBuild.buildCauses.shortDescription[0]
这将返回正确的构建触发器GitHub pull request comment
。因此,对于也遇到此问题的任何人,这就是我修复它的方法
pipeline {
agent { label 'mac' }
stages {
stage ('Test') {
when {
expression {
currentBuild.buildCauses.shortDescription[0] == "GitHub pull request comment"
}
}
steps {
sh 'bundle exec fastlane test'
}
}
}
}
推荐阅读
- android - 仅使用一个 Firebase 项目,我可以为同一移动设备上的不同应用设置不同的令牌吗?
- sql - 错误地使用连接?
- facebook - 如何在 2018 年从许多 Facebook 页面(来自餐馆)获取对服务进行评分的评论,以进行情绪分析?(推特不够好)
- python - 当其中一些通过 sudo pip3 安装其他包时,如何删除 pip 安装的所有包
- python - 熊猫数据框中行中的唯一文本
- javascript - 如何从传递给其兄弟组件的下拉框中获取 ref 值?
- assembly - RISC-V:PC 绝对值与 PC 相对值
- java - 线程“main”中的异常 java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version
- python - django比较时间字段
- sql - 新手 SQL 学习者(内连接)