首页 > 解决方案 > 如何验证特定作者在管道声明性脚本中所做的代码更改

问题描述

我们有包含多个项目的存储库,每当我们发布脚本时,都会更改所有具有特定版本的快照。

这可能会导致构建詹金工作。

目前我正在使用作业并浏览项目列表并通过以下 shell 脚本进行限制。

我也尝试了以下脚本,但变量打印为空,我正在通过管道插件的“管道脚本”选项进行测试。(内联脚本)

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
            }
        }
    }
}

标签: jenkinsjenkins-pipeline

解决方案


我已经分步介绍了以下脚本,如果有人有更好的解决方案请更新

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"                                                                     
    }
}

推荐阅读