What I want that in creation of tags or branch (even if no change in tags/branch) , there need to be a build triggered automatically . Pls help
#!groovy
pipeline {
agent none
stages {
stage("Checkout") {
agent any
steps {
checkout scm
}
}
stage('Maven Install and Code Build') {
agent any
environment {
def GIT_TAG = sh(returnStdout: true, script: 'git log -n 1 --pretty=format:\'%H\'').trim()
}
steps {
sh "mvn clean package -DskipTests --settings settings.xml"
}
/*agent {
docker {
image 'maven:3.5.0'
}
}
steps {
sh "mvn clean package --settings settings.xml"
}*/
}
stage('Unit Test') {
agent any
steps {
sh "mvn test --settings settings.xml"
}
}
stage('Docker Build') {
agent any
steps {
sh 'docker build --build-arg jarfile=framework-0.0.1-SNAPSHOT.jar ' +
sh 'sh clear-dangling-builds.sh'
}
}
stage('Automated Integration Test') {
agent any
steps {
echo 'Ship to Integration test Env'
echo 'Deploy the docker here '
echo 'Run Integration test suite'
input message: 'Finished Integration Test ? (Click "Proceed" to continue)'
echo 'Stop docker in the integration env #################'
}
}
stage('Publish Docker image On Tag') {
agent any
when { buildingTag() }
steps {
withCredentials([usernamePassword(credentialsId: 'gitlabRepo', passwordVariable: 'dockerRepoPassword', usernameVariable: 'dockerRepoUser')]) {
}
}
}
stage('Deploy in Dev Environment') {
agent any
steps {
input message: 'You want to deploy in which env (dev) ? (Click "Proceed" to continue)'
echo 'Checkout docker from registry'
echo 'Connect to the desired environment'
echo 'Deploy here .. probaly use some plugin to deploy in the container or container orchestration'
}
}
stage('Deploy in CIT/E2E/Prod Environment') {
agent any
when { buildingTag() }
steps {
script {
// Show the select input modal
def INPUT_PARAMS = input message: 'Please Provide Parameters', ok: 'Next',
parameters: [
choice(name: 'ENVIRONMENT', choices: ['CIT','E2E','PROD','NONE'].join('\n'), description: 'Please select the Environment'),
string(defaultValue: "NONE", description: 'What is the tag id?', name: 'TAG_ID')]
env.ENVIRONMENT = INPUT_PARAMS.ENVIRONMENT
env.TAG_ID = INPUT_PARAMS.TAG_ID
}
input message: 'You want to deploy in $env.ENVIRONMENT for commit-id $env.TAG_ID ? (Click "Proceed" to continue)'
echo 'Checkout docker from registry'
echo 'Connect to the desired environment'
echo 'Deploy here .. probaly use some plugin to deploy in the container or container orchestration'
}
}
}
}