Skip to content

Instantly share code, notes, and snippets.

@amanpruthi
Created June 9, 2022 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amanpruthi/8b16d9054731dd602e4257419f47dcfb to your computer and use it in GitHub Desktop.
Save amanpruthi/8b16d9054731dd602e4257419f47dcfb to your computer and use it in GitHub Desktop.
def LABEL_ID = "yourappname-${UUID.randomUUID().toString()}"
def BRANCH_NAME = "<Your branch name>"
def GIT_URL = "<Your git url>"
// Start Agent
node(LABEL_ID) {
stage('Checkout') {
doCheckout(BRANCH_NAME, GIT_URL)
}
stage('Build') {
...
}
stage('Tests') {
...
}
}
// Kill Agent
// Input Step
timeout(time: 15, unit: "MINUTES") {
input message: 'Do you want to approve the deploy in production?', ok: 'Yes'
}
// Start Agent Again
node(LABEL_ID) {
doCheckout(BRANCH_NAME, GIT_URL)
stage('Deploy') {
...
}
}
def doCheckout(branchName, gitUrl){
checkout([$class: 'GitSCM',
branches: [[name: branchName]],
doGenerateSubmoduleConfigurations: false,
extensions:[[$class: 'CloneOption', noTags: true, reference: '', shallow: true]],
userRemoteConfigs: [[credentialsId: '<Your credentials id>', url: gitUrl]]])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment