0

I'm new to multi-branch pipeline concept and trying to implement in our project where we are running our jenkins builds inside docker containers.

We have a requirement where all build against "develop" branch should be doing build and docker image creation. Where as the rest created "feature/hot-fix" branches has to do only build.

I wrote a Jenkinfile file in a following way

node {
 checkout scm

 if (env.BRANCH_NAME == 'develop') {

   stage ('Stage for develop') {

     echo  "Build,create an docker-image"
   }

 }

 else if (env.BRANCH_NAME == 'feature_branch') {

   stage ('Stage for feature branch') {

     echo "only build"
   }

 }

 else {
   echo "Branch branch not found"
 }

The problem here is we are hard-coding the feature branch names and this could be a problem if someone creates a branch with different names and Jenkinsfile will fail to identify it.

I'm trying to write in such a way that Jenkinsfile has to identify the newly created branch automatically and should run a build against it.

Any help would be appreciated.

R.V
  • 199
  • 1
  • 3
  • 13

1 Answers1

0
node{
    checkoutscmscript{
        if(env.BRANCH_NAME=='develop'){
            stage('Stagefordevelop'){
                echo"Build,create an docker-image"
            }
        }else{
            stage('Stageforfeature/hotfixbranch'){
                echo" executing on ${env.BRANCH_NAME} "echo"only build"
            }
        }
    }
}
myborobudur
  • 4,385
  • 8
  • 40
  • 61
R.V
  • 199
  • 1
  • 3
  • 13
  • Not sure what you want to achieve. What should happen to differently-named branches? Did you think about the possibility to have different versions of the Jenkinsfile in different branches? – Joerg S Feb 28 '18 at 07:37
  • My moto was to do only compile,test and package for all the branches except the master and develop branches. And post to successful package, it has to be merged with the develop branch where it will do a build and release the artifact and creates the docker image . – R.V Feb 28 '18 at 09:01