如何使用Jenkins Pipeline 获取git commit id?
需求:jenkins pipeline获取git commit id 作为docker中imagesTag标识
解决方法:
使用git方法获取commit id
git rev-parse HEAD (完整)
或者
git rev-parse --short HEAD (简短)
Pipeline中
script {
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
}

本文介绍了如何在 Jenkins Pipeline 中使用 `git rev-parse` 命令获取 Git commit ID,以便将其用作 Docker image 的 tag 标识。示例代码展示了如何使用 `git rev-parse --short HEAD` 获取简短的 commit ID,并将其赋值给变量 `build_tag` 进行后续使用。
最低0.47元/天 解锁文章
1320

被折叠的 条评论
为什么被折叠?



