44-Jenkins-获取构建变更信息
Posted 爱学习de测试小白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了44-Jenkins-获取构建变更信息相关的知识,希望对你有一定的参考价值。
获取构建变更信息
前言
- 本篇来学习Jenkins中基于对先前构建的更改信息的获取
使用示例
说明:
- git 信息需替换成自己的即可
- 获取的是Jenkins当次构建与上一次构建的git变更信息
- 如果前一个失败并被重新触发,则 changeSet 将为空
pipeline
agent any
stages
stage('pull')
steps
git branch: '分支名', credentialsId: '认证信息', url: 'gitlab地址'
stage('Get Last Commit Details')
steps
script
List<String> changes = getChangedFilesList()
println ("Changed file list: " + changes)
String gitCommitId = getGitcommitID()
println("GIT CommitID: " + gitCommitID)
String gitCommitAuthorName = getAuthorName()
println("GIT CommitAuthorName: " + gitCommitAuthorName)
String gitCommitMessage = getCommitMessage()
println("GIT CommitMessage: " + gitCommitMessage)
@NonCPS
List<String> getChangedFilesList()
def changedFiles = []
for ( changeLogSet in currentBuild.changeSets)
for (entry in changeLogSet.getItems())
changedFiles.addAll(entry.affectedPaths)
return changedFiles
@NonCPS
String getGitcommitID()
gitCommitID = " "
for ( changeLogSet in currentBuild.changeSets)
for (entry in changeLogSet.getItems())
gitCommitID = entry.commitId
return gitCommitID
@NonCPS
String getAuthorName()
gitAuthorName = " "
for ( changeLogSet in currentBuild.changeSets)
for (entry in changeLogSet.getItems())
gitAuthorName = entry.authorName
return gitAuthorName
@NonCPS
String getCommitMessage()
commitMessage = " "
for ( changeLogSet in currentBuild.changeSets)
for (entry in changeLogSet.getItems())
commitMessage = entry.msg
return commitMessage
脚本权限问题
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method hudson.plugins.git.GitChangeSet getAuthorName
- 解决方案
点击 “Administrators can decide whether to approve or reject this signature” 进入授权页,点击 Approve 即可
查看输出
以上是关于44-Jenkins-获取构建变更信息的主要内容,如果未能解决你的问题,请参考以下文章
融合数据库生态:利用 EventBridge 构建 CDC 应用