The following Jenkinsfile:
pipeline {
agent any
stages {
stage( "1" ) {
steps {
script {
def br = "demo_branch"
def clone_url = "ssh://[email protected]:7999/spc/my_prj.git"
def cred_id = "ssh_cred_id"
def relative_dir = "my_prj"
checkout([$class: 'GitSCM',
branches: [[name: br]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: relative_dir]],
submoduleCfg: [],
userRemoteConfigs: [[url: clone_url,
credentialsId: cred_id]]])
}
}
}
}
post {
always {
script {
echo "the end"
}
}
}
}
...results in the directory /home/jenkins/workspace/job/my_prj/ being created in my Jenkins server, and that directory contains my cloned git repo.
I would like to cd to this directory, run the command git rev-parse --abbrev-ref HEAD and get the value "demo_branch", but instead I get the value "HEAD". I am pretty certain that this is because the Jenkinsfile checkout command is checking out refs/heads/demo_branch instead of demo_branch. I.e.:
user@server:/home/user# cd /home/jenkins/workspace/job/my_prj/
user@server:/home/jenkins/workspace/job/my_prj# git rev-parse --abbrev-ref HEAD
HEAD
user@server:/home/jenkins/workspace/job/my_prj# git checkout demo_branch
Switched to branch 'demo_branch'
Your branch is up-to-date with 'origin/demo_branch'.
user@server:/home/jenkins/workspace/job/my_prj# git rev-parse --abbrev-ref HEAD
demo_branch
Is there a way I can get the Jenkins checkout command to check out demo_branch instead of refs/heads/demo_branch?