in a jenkinsfile I have a declarative pipeline to build two Maven projects consecutively checked out from the Github repositories
repo2 (https://github.com/MaxHoefl/repo2)
repo1 (https://github.com/MaxHoefl/repo1)
How can I checkout a Github repo on a specific branch and even a specific commit on that branch?
pipeline {
agent any
tools {
maven "localMaven"
jdk "localJDK"
git "localGit"
}
stages {
stage('Checkout-Repo2') {
steps {
git 'https://github.com/MaxHoefl/repo2.git'
sh "echo {$env.GIT_URL}"
}
}
stage('Build-Repo2') {
steps {
sh "mvn clean install"
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
stage('Checkout-Repo1') {
steps {
git 'https://github.com/MaxHoefl/repo1.git'
sh "echo {$env.GIT_URL}"
}
}
stage('Build-Repo1') {
steps {
sh "mvn clean install"
}
}
}
post {
success {
echo "Build ID: {$env.BUILD_ID}"
echo "Jenkins URL: {$env.JENKINS_URL}"
echo "Jobname: {$env.JOB_NAME}"
echo "Branch: {$env.BRANCH_NAME}" //null
echo "Change id: {$env.CHANGE_ID}"
}
failure {
}
always {
echo 'Cleaning up....'
deleteDir()
}
}
}
Thanks a lot!
Instead of using git
command
stage('Checkout-Repo2') {
steps {
git 'https://github.com/MaxHoefl/repo2.git'
}
}
I tried using the more general checkout
command
stage('Checkout-Repo2') {
steps {
checkout([$class: 'GitSCM', branches: [[name: ''a5e1ddd4e45aeb396b44beece370f891bd0c7fe5'']],
userRemoteConfigs: [[url: 'https://github.com/MaxHoefl/repo2.git']]])
}
}
This works. Will try to also include the branch name