Multi branch pipeline - build is failing while creating new branch or tag

9 views
Skip to first unread message

Anish Kuti

unread,
Aug 2, 2019, 3:06:01 PM8/2/19
to Jenkins Users
Hi ,
I am using Jenkins ver. 2.176.2 and deployed in EC2 (Ubuntu) . I am using multi branch pipeline . The jenkins file is as below .  While I am creating a new branch or tag I was expecting to start a build.  But it is not happening . 

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 



In creation of new tag -  it is showing below and no build is triggering
No changes in any of the builds, or multiple SCMs in use.
In creation of new branch  -  it is showing below and build is falling 

> git fetch --no-tags --progress g...@gitlab.com:tcscmiiag/nextgenordermgmt/frameworkcode.git +refs/heads/*:refs/remotes/origin/*
Checking out Revision fc72acd2362cc1dd00d4b1ba0125da7c9e2d3aca (feature_Z_branch)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f fc72acd2362cc1dd00d4b1ba0125da7c9e2d3aca
Commit message: "updated jenkins File"
First time build. Skipping changelog.


#!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 ' +
                        '-t registry.gitlab.com/tcscmiiag/nextgenordermgmt/frameworkcode'+":$BUILD_NUMBER"+' --pull=true --file=Dockerfile .'
                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')]) {
                    sh "docker login registry.gitlab.com -u $dockerRepoUser -p $dockerRepoPassword"
                    sh "docker push registry.gitlab.com/tcscmiiag/nextgenordermgmt/frameworkcode:$GIT_TAG"

                }
            }
        }
       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'


            }
        }
    }
}

Reply all
Reply to author
Forward
0 new messages