Skip to content

Instantly share code, notes, and snippets.

@zdtsw
Last active November 29, 2017 12:26
Show Gist options
  • Select an option

  • Save zdtsw/3060bf95855f8b02a3fa724aa531b6a0 to your computer and use it in GitHub Desktop.

Select an option

Save zdtsw/3060bf95855f8b02a3fa724aa531b6a0 to your computer and use it in GitHub Desktop.
some basic takeaways from Declarative pipeline syntax for jenkins 2.0, see detail https://jenkins.io/doc/book/pipeline/syntax/ and https://issues.jenkins-ci.org/browse/INFRA-1053
#!groovy
@Library('deliveryLib')_
pipeline{
agent {}
environment{ VAR = credentials(VAL)}
options{}
tools{maven '****'}
triggers{ cron('H */4 * * 1-5') }
parameters{}
stages{
stage('*'){
environment{}
agent{}
when{
branch '***'
environment name: '***' value:'****'
expression: express_true
not:
allOf:
anyOf:
}
tools{git '****'}
failFast true
parellel{
stage('*'){}
stage('*'){}
}
steps{
echo '****'
sh '****'
script{}
}
post{}
}
stage('*'){
}
post{}
}
dont forget _ in the end as annotation
Required
Required , can be any of such value: any none label 'my-defined-label' node { label 'labelName' } docker{ image 'maven:3-alpine' label 'my-defined-label' args '-v /tmp:/tmp' } dockerfile true
credentials use secret Text contents.
can be any of such value: buildDiscarder disableConcurrentBuilds() overrideIndexTriggers() skipDefaultCheckout skipStagesAfterUnstable() timestamps retry(3) timeout(time: 1, unit: 'HOURS')
need to pre-config in Manage Jenkins → Global Tool Configuration
can be any of such value: cron('H */4 * * 1-5') pollSCM('H */4 * * 1-5') or upstream(upstreamProjects: 'job1,job2', threshold: hudson.model.Result.SUCCESS)
can be any of such value: string booleanParam
Required
Required
need to pre-config in Manage Jenkins → Global Tool Configuration
to make stage failed if any of the stage in the parellel {} is failed, like a shortcut
https://jenkins.io/doc/pipeline/steps/ for detail
example what can be used in step
example what can be used in step
script is to block out old style scripted jenkins' file format
can be any of such value: always changed failure success unstable aborted
c
an be any of such value: always changed failure success unstable aborted
to use parameter in pipeline block, you wont see the parameter with "build with parameter" for the very first time.
e.g
pipeline {
agent any
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
}
stages {
stage('Example') {
steps {
echo "Hello ${params.PERSON}"
}
}
}
To have this as the whole jenkins file, you need to click "Build" to have a green run, then jenkins would scan such parameters
and make them into the "old style" config also be valid for the 2nd time which showing a "Build with parameter"
retry(3) is on the pipeline block level, which means, if you choose to use it, it would start the whole pipeline if any part failed
Limitation for sharedlib:
Only entire pipeline`s can be defined in shared libraries as of this time. This can only be done in `vars/*.groovy, and only in a call method. Only one Declarative Pipeline can be executed in a single build, and if you attempt to execute a second one, your build will fail as a result.
This probably need to have much rework for what already in the sharedlib function
BUG:
cannot accept Cape for the groovy file
e.g vars/Logs.groovy not working, with same content vars/logs.groovy works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment