0

Below how my Jenkinsfile looks. I am trying to push or do sth when a branch name is the master is. But in this way I am getting null as a branch name. Below is my entire Jenkinsfile

   node () {
        def app
        stage('Clone repository') {
            checkout scm
        }
        stage('Build image') {

            app = docker.build("runtime-development-tools")
            echo "${env.BRANCH_NAME}"
        }
        stage('Push image') {
            if(env.BRANCH_NAME == "master"){
              echo "Hello master"
             // do something


            }
          }
        }

Other links in StackOverflow, unfortunately, did not help me. My Jenkinsfile and other resources are in git repo. I have multi-branch and I want to perform a specific action if it's master branch.

  • Is it a parameterized build with branch name as one parameter? Are you using multibranch pipeline? See if this helps: https://stackoverflow.com/questions/43770058/jenkins-pipeline-branch-name-returns-null – Technext Jun 18 '20 at 15:18
  • @Technext I saw that link as well. I do use the multi-branch pipeline. please see the update. thanks for the response –  Jun 18 '20 at 20:08

1 Answers1

0

In Jenkins there is two pipeline options:

New Item -> Pipeline --> env.BRANCH_NAME return branch null
New Item -> Multibranch Pipeline -

-> env.BRANCH_NAME return branch master or branch name