Jenkins获取commit id

获取完整commit id(如:bb4f92a7d4cbafb67d259edea5a1fa2dd6b4cc7a)

git rev-parse HEAD

获取short commit id(如:bb4f92a)

git rev-parse --short HEAD

完成pipeline

pipeline {
   agent any

options{  timestamps () }
environment {


COMMT= sh(  returnStdout: true, script: 'git log --oneline -1 | awk \'{print \$1}\'')
HTTPD= sh(  returnStdout: true, script: 'git rev-parse  HEAD')

}

   stages {
      stage('get code ') {
         steps {
        checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: '[email protected]:new/dfc.git']]])
            
         }
      }
      

stage("Commit -ID"){
      	steps{
      		echo "${COMMT}"
      	     
            echo "${HTTPD}"
      		}
      	} 

      	}

      }

你可能感兴趣的:(Jenkins)