jenkins - Jenkinsfile and different strategies for branches -


i'm trying use jenkins file our builds in jenkins, , have following problem. have 3 kind of builds:

  • pull-request build - merged master after code review, , if build works
  • manual pull-request build - build same above, can triggered manually user (e.g. in case have unstable test)
  • an initial continuous deliver pipeline - build code, deploy repository, install artifacts repository on target server , start application there

how should contain of above builds single jenkinsfile. right idea have make giant if check branch , steps.

so have 2 questions:

1. appropriate way in jenkinsfile?

  1. how name of executing branch in multi-branch job type?

for reference, here's current jenkinsfile:

def servers = ['server1', 'server2']  def version = "1.0.0-${env.build_id}"  stage 'build, ut, it' node {     checkout scm     env.path = "${tool 'maven'}/bin:${env.path}"     withenv(["path+maven=${tool 'maven'}/bin"]) {         sh "mvn -e org.codehaus.mojo:versions-maven-plugin:2.1:set -dnewversion=$version -dgeneratebackuppoms=false"         sh 'mvn -e clean deploy'         sh 'mvn -e scm:tag'     } }   def nodes = [:] (int = 0; < servers.size(); i++) {     def server = servers.get(i)     nodes["$server"] = {         stage "deploy int ($server)"         node {             sshagent(['some-id']) {                 sh """                 ssh ${server}.example.com <<end                 hostname                 /apps/stop.sh                 yum  -y update-to my-app.noarch                 /apps/start.sh                 end""".stripindent()             }         }     } }  parallel nodes 

edit: removed opinion based question

you can add if statement multiple stages if want skip multiple stages according branch in:

if(env.branch_name == 'master'){      stage("upload"){         // artifact repository upload steps here         }      stage("deploy"){         // deploy steps here        }      } 

or, can add individual stage in:

stage("deploy"){   if(env.branch_name == 'master'){    // deploy steps here   } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -