简体   繁体   English

在 Git 签出后获取 Git 提交 ID - Jenkins(Git 插件)

[英]Get Git Commit ID after Git Checkout - Jenkins (Git Plugin)

I'm very new to Jenkins .我对Jenkins很陌生。

在此处输入图像描述

I'm using this built-in plugin to do Git Checkout with my GitHub credentials, what I wanna achieve is somehow get the git commit id as a variable so that I can use that commit id on any build step of my pipeline.我正在使用这个内置插件使用我的 GitHub 凭据执行Git Checkout ,我想要实现的是以某种方式获取 git commit id作为变量,以便我可以在管道的任何构建步骤中使用该commit id

I searched but couldn't find any documentation for this plugin.我搜索了但找不到此插件的任何文档。

pipeline {
    agent any

    stages {
        stage('Git Checkout') {
            steps {
                git(
                    branch: 'dev', 
                    credentialsId: 'Aniket-IN-Github', 
                    url: 'https://github.com/ComputerReflex/ComputerReflex-Laravel-React.git'
                )
                 # Want to get the commit id.
                echo "Git Commit # ${GIT_COMMIT}"
            }
        }
    }

}


Thank you so much in advance:)非常感谢你提前:)

you can use this after checkout ( kind of workaround)您可以在结帐后使用它(一种解决方法)

env.GIT_COMMIT = sh(script: "git rev-parse HEAD ", returnStdout: true).trim() 
echo env.GIT_COMMIT

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

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