简体   繁体   English

使用jenkins管道脚本找出最后的提交

[英]To find out last commit using jenkins pipeline script

We are using below command to find out the last commit to the git 我们正在使用以下命令来查找对git的最后一次提交

{ git log -1 --pretty=format:'%an'; {git log -1 --pretty = format:'%an'; echo "@xyzcompany.com, developer@xyzcompany.com"; 回显“ @ xyzcompany.com,developer @ xyzcompany.com”; } | } | xargs -I{} echo {} | xargs -I {} echo {} | sed 's/\\n//' sed's / \\ n //'

Note: this command is working in CLI in jenkins workspace project. 注意:此命令在jenkins工作区项目的CLI中有效。

How to inject this command in jenkins pipeline script?? 如何在詹金斯管道脚本中注入此命令?

You can just use an sh to execute the command. 您可以只使用sh执行命令。 If you are using declarative syntax (starting with pipeline instead of node ) I'd suggest to do that in the environment , so you can read the result in all stages of your pipeline: 如果您使用声明性语法(以pipeline而不是node开头),我建议在environment中这样做,这样您就可以在管道的所有阶段读取结果:

environment {
    COMMIT = sh(script: '{ git log -1 --pretty=format:\'%an\'; echo "@xyzcompany.com, developer@xyzcompany.com"; } | xargs -I{} echo {} | sed \'s/\n//\'', returnStdout: true).trim()
}

Or –if you use scripted syntax– you just declare a variable: 或者–如果使用脚本化语法–只需声明一个变量:

def commit = sh(script: '{ git log -1 --pretty=format:\'%an\'; echo "@xyzcompany.com, developer@xyzcompany.com"; } | xargs -I{} echo {} | sed \'s/\n//\'', returnStdout: true).trim()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM