How to re-write a Jenkins DSL file as a Jenkins pipeline jenkinsfile? -


i have following jenkins dsl file:

if (params["build_snapshot"] == "true") {     parallel(         {             build("company-main-build-snapshot")         },         {             build("1-company-worker-build-snaphsot", worker_name: "sharding-worker")         }     ) } parallel (     {         build("company-deployment-info",             api_key: "aaaaa5dd4cd58b94215f9cddd4441c391b4ddde226ede98",             app: "company-staging-app")     },     {         build("company-salt-role-deploy",                 env: "staging",                 role: "app")     },     {         build("company-deployment-info",             api_key: "aaaaa5dd4cd58b94215f9cddd4441c391b4ddde226ede98",             app: "company-staging-shardwork")     },     {         build("company-salt-workers-deploy",                 environment: "staging",                 worker_type: "shardwork")     } )  if (params["rest_test"] == "true") {     build("company_staging_python_rest_test") } 

my task convert/rewrite workflow file content jenkins pipeline jenkinsfile.

i have example files reference i'm having hard time understanding how should begin...

can please shed light on subject?

first, have @ jenkins pipeline documentation, great start , providing whole bunch of information such build parameters usage or parallel steps.

here few more hints explore :

parameters

just use parameter name variable such :

if (build_snapshot) {     ... } 

call other jobs

you can use build step such :

build job: '1-company-worker-build-snaphsot', parameters: [stringparam(name: 'worker_name', value: "sharding-worker")] 

use functions

instead of calling downstream jobs using build steps each time, might want consider using pipeline functions groovy script, either current project or external, checked out groovy script.

as example, replace second job call :

build("1-company-worker-build-snaphsot", worker_name: "sharding-worker") 

to :

git 'http://urltoyourgit/projectcontainingyourscript' pipeline = load 'global-functions.groovy' pipeline.buildsnapshot("sharding-worker") 

...of course init phase (git checkout , pipeline loading) needed once before can call external scripts functions.

in short

to sum little bit, code converted along these lines :

node {     git 'http://urltoyourgit/projectcontainingyourscript'     pipeline = load 'global-functions.groovy'      if(build_snapshot) {         parallel (             phase1: { pipeline.buildmainsnapshot() },             phase2: { pipeline.buildworkersnapshot("sharding-worker") }         )     }     parallel (         phase1: { pipeline.phase1(params...) },         phase2: { pipeline.phase2(params...) },         phase3: { pipeline.phase3(params...) },         phase4: { pipeline.phase4(params...) }     )     if (rest_test) {         pipeline.finalstep()     } } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -