jenkins - 如何验证特定作者在管道声明性脚本中所做的代码更改
问题描述
我们有包含多个项目的存储库,每当我们发布脚本时,都会更改所有具有特定版本的快照。
这可能会导致构建詹金工作。
目前我正在使用作业并浏览项目列表并通过以下 shell 脚本进行限制。
- 我如何在声明性管道中实现相同的目标,以分别构建子项目并确定更改的作者?
如果我手动运行声明性能够识别代码有变化?
对于 cat projects-list.txt 中的文件;如果测试 -d $file; 然后
echo "Checking project $file" AUTHOR=$(git log -1 --format='%an' -- "$file") if [ "${AUTHOR}" != "release" ]; then echo "Detected changes in project $file" cd $file echo "Building project $file" mvn clean install -U`
我也尝试了以下脚本,但变量打印为空,我正在通过管道插件的“管道脚本”选项进行测试。(内联脚本)
pipeline {
agent any
stages {
stage ('checkout') {
steps {
git url: 'https://my.com/scm/java/my.git'
}
}
stage('Build') {
steps {
echo 'Building.. branch'+env.BRANCH_NAME
echo env.CHANGE_AUTHOR
echo env.CHANGE_AUTHOR_DISPLAY_NAME
}
}
}
}
解决方案
我已经分步介绍了以下脚本,如果有人有更好的解决方案请更新
script {
def changeLogSets = currentBuild.changeSets
def commitAuthor =""
def commitMsg =""
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
commitAuthor = "${entry.author}"
commitMsg = "${entry.msg}"
echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
}
}
if(commitAuthor == 'release' || commitMsg.contains("INTERIM") ) {
echo "condition meet"
}
}
推荐阅读
- java - 带有微服务和 Docker-Compose 错误的 Spring Cloud Stream Kafka
- python - “值”对象没有属性“保存”
- clang-format - 我可以禁用 Clang 格式中某些宏的所有调用的格式吗?
- sql - 如何在存储过程中从 VARIABLE 表中选择数据
- mysql - mySQL 选择随时间变化 X% 的价格记录
- java - 无法使用本地 JDBC 应用程序连接到安装在 aws 中的 mysql
- sockets - 在 Windows 上使用来自 GNU Emacs 的 Emacs Lisp 打开 UDP / 数据报套接字
- html - 为什么我无法使用 xhtml 架构检测节点 Xpath 中的属性信息?
- python - Python中带有条件的列表的平均值
- python - 使用 DTW 对不规则时间序列数据进行下采样/上采样