jenkins-declarative-pipeline

Jenkins: How to skip a specific stage in a multibranch pipeline?

岁酱吖の 提交于 2019-12-11 18:15:03
问题 We have "stage (build)" on all our branches. Temporarily how can we skip this stage to run on all our branches in multibranch pipeline. I know one solution is use when condition on stage and ask all developers to pull that branch into their branch. But thats lot of work and coordination. Instead I am looking for a global configuration where we can simply skip the stage by name on any branch. 回答1: It sounds like you keep the Jenkinsfile alongside the code, but want to change how the

how do i get a variable out of powershell in jenkins declarative pipeline?

孤街醉人 提交于 2019-12-11 17:19:10
问题 steps { script{ env.StorysTested = '' try{ powershell(''' //some code here foreach ( $item in $Comments ) { //some code here //assigning a new value to StoryTested env variable $env:StorysTested = "some value" } //below line works fine and displays the value Write-Output "Stories tested : $env:StorysTested" ''') //below null value is displayed for StorysTested`` echo " From Grrovy : ${env.StorysTested}" } catch(err) { throw err } } I am using a jenkins declarative pipeline. In the above code

Run nightly jobs on multibranch pipeline with declarative Jenkinsfile

落花浮王杯 提交于 2019-12-10 21:03:49
问题 Jenkins version 2.121.2 I have a multi-branch pipeline set up. I am using a declarative Jenkinsfile. I have a set of tests which take a long time to run. I want these to run over night for any branches which have changes. I have tried a few things but my current failing attempt is: Under the job > configure, I have enabled 'Suppress automatic SCM triggering' Have 'Scan Multibranch Pipeline Triggers' > 'Periodically if not otherwise run' set to 1 minute (just for testing, I will increase this

Clean way to exit declarative Jenkins pipeline as success?

∥☆過路亽.° 提交于 2019-12-10 13:53:33
问题 I am looking for the cleanest way to exit a declarative Jenkins pipeline, with a success status. While exiting with an error is very neat using error step , I couldn't find any equal way to exit with success code. E.G: stage('Should Continue?') { when { expression {skipBuild == true } } steps { echo ("Skiped Build") setBuildStatus("Build complete", "SUCCESS"); // here how can I abort with sucess code? // Error Would have been: // error("Error Message") } } stage('Build') { steps { echo "my

Jenkins declarative pipeline: Execute stage when file has changed or a new branch was created

六眼飞鱼酱① 提交于 2019-12-10 13:09:04
问题 I like to build a stage in a declarative pipeline only when certain files have changed. This can be achieved by the following pipeline: pipeline { agent any stages { stage('checkout') { steps { checkout scm } } stage('build & push container') { when { anyOf { changeset 'Dockerfile' } } steps { echo "Building..." } } } } This does not build when a new branch is created as the changeset is still empty in Jenkins when a branch is built for the first time. How can I define a when condition that

jenkins docker plugin in pipeline use -u flag, how is possible to not using

喜夏-厌秋 提交于 2019-12-10 09:57:23
问题 I'm using jenkins version 2.89.1 with docker plugin. In a stage of declarative pipeline I launch a docker container with ansible 2.4.x installed in order to run some playbooks as follow: agent { docker { image 'myself/ansible:1.0.3' registryUrl 'https://my-artifactory-pro' registryCredentialsId 'my-credentials' args '-v /var/lib/jenkins/workspace/myworkspace:/tmp/' + ' -v /var/lib/jenkins/.ssh:/root/.ssh' } } steps { echo 'Deploying Ansible Server via docker image' sh "ansible-playbook -i

Jenkins declarative pipeline. Conditional statement in post block

ε祈祈猫儿з 提交于 2019-12-07 21:14:39
问题 Have a Jenkins pipeline. Need/want to send emails when build succeeds. Email about all branches to maillist-1 and filter builds of master branch to maillist-master . I tried using if and when statements-steps but both of them fail in post block. pipeline { agent ... stages {...} post{ success{ archiveArtifacts: ... if( env.BRANCH_NAME == 'master' ){ emailext( to: 'maillist-master@domain.com' , replyTo: 'maillist-master@domain.com' , subject: 'Jenkins. Build succeeded :^) 😎' , body: params

Template docker agent in jenkins Declarative pipeline

[亡魂溺海] 提交于 2019-12-07 18:04:49
问题 I have a Jenkinsfile for a declarative pipeline that uses docker agents. A number of the steps use a docker agent and it is a bit repetitive adding the same agent for these steps e.g. pipeline { agent any stages { stage('Stage 1') { steps { //Do something } } stage('Stage 2') { agent { docker { image 'jenkins/jenkins-slave:latest' reuseNode true registryUrl 'https://some.registry/' registryCredentialsId 'git' args '-v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -e HOME=${WORKSPACE}' } }

Jenkins declarative pipeline. Conditional statement in post block

不羁岁月 提交于 2019-12-06 13:28:19
Have a Jenkins pipeline. Need/want to send emails when build succeeds. Email about all branches to maillist-1 and filter builds of master branch to maillist-master . I tried using if and when statements-steps but both of them fail in post block. pipeline { agent ... stages {...} post{ success{ archiveArtifacts: ... if( env.BRANCH_NAME == 'master' ){ emailext( to: 'maillist-master@domain.com' , replyTo: 'maillist-master@domain.com' , subject: 'Jenkins. Build succeeded :^) 😎' , body: params.EmailBody , attachmentsPattern: '**/App*.tar.gz' ) } emailext( to: 'maillist-1@domain.com' , replyTo:

Template docker agent in jenkins Declarative pipeline

亡梦爱人 提交于 2019-12-05 22:44:14
I have a Jenkinsfile for a declarative pipeline that uses docker agents. A number of the steps use a docker agent and it is a bit repetitive adding the same agent for these steps e.g. pipeline { agent any stages { stage('Stage 1') { steps { //Do something } } stage('Stage 2') { agent { docker { image 'jenkins/jenkins-slave:latest' reuseNode true registryUrl 'https://some.registry/' registryCredentialsId 'git' args '-v /etc/passwd:/etc/passwd -v /etc/group:/etc/group -e HOME=${WORKSPACE}' } } steps { //Do something } } stage('Stage 3') { steps { //Do something } } stage('Stage 4') { agent {