jenkins-pipeline

jenkins declarative pipeline set variables derived from parameters

不羁的心 提交于 2019-12-08 15:07:40
问题 I am using a declarative pipeline in a Jenkinsfile but I would like to derive some variables from a parameter. For example given: parameters { choice(name: 'Platform',choices: ['Debian9', 'CentOS7'], description: 'Target OS platform', ) } I would like to add a block like: script { switch(param.Platform) { case "Centos7": def DockerFile = 'src/main/docker/Jenkins-Centos.Dockerfile' def PackageType = 'RPM' def PackageSuffix = '.rpm' break case "Debian9": default: def DockerFile = 'src/main

How to merge a successful build of a pull request using a Jenkinsfile

时光怂恿深爱的人放手 提交于 2019-12-08 13:32:44
问题 TL;DR: Given the following declarative Jenkinsfile, how can I merge the pull request following a successful build? http://pastebin.com/uivA0MqF In the (Multibranch) Job configuration, under Branch Source > Advanced I have the following setup: And in GitHub I have a web hook that listens to pull request and push events. Edit: I have attempted the following, but it currently fails with a syntax error: def gitPullRequestNumber = null ... ... stage ("Merge pull request") { steps {

Jenkinsfile - agent matching multiple labels

淺唱寂寞╮ 提交于 2019-12-08 11:32:27
In my declarative pipeline, i need to select a node matching 2 labels. I tried something like this agent { label 'label1 && label2'} But i get an error that there are no nodes . I have a node with 2 labels label1 and label2 associated. Started by user admin Running in Durability level: MAX_SURVIVABILITY [Pipeline] node Still waiting to schedule task There are no nodes with the label ‘label1&&label2’ I know that i could temportailiy fix this by creating a 3rd label label1-2 and associate it with agent in the pipeline. Is there any proper way to fix this? Ok..figured it out. agent {label "label1

Pass Jenkins Pipeline parameters from a Jenkins job?

喜夏-厌秋 提交于 2019-12-08 11:20:57
问题 I have a Jenkins Pipeline script being used to deploy lambdas. Right now the user passes the parameters to the job to kick it off. I want to automate the job a bit more and create a process where the job triggers and the parameters are passed via a JSON file to kick off the job. I'm not clear on how to proceed I've seen that maybe JsonSlurper could be used, but not sure if that is the ideal solution for the process. Does anyone have a good solution that I could implement? 回答1: I would

embed image in email body jenkins pipeline

隐身守侯 提交于 2019-12-08 09:33:25
I need to add an image in email as email body not as attachment, from Jenkins via pipeline. I am using emailext plugin in Jenkins pipeline, below is the code I am using. emailext ( subject: "test email", body: """ <html> <body> <p>please find attached score: Job '${env.JOB_NAME}':</p> <p> The last commit was by ${last_commit_user} </p> <p>Please check jenkins console at "</p> <p> For detailed report on this analysis, visit "</p> </body> </html> """, to: email_recipients, attachmentsPattern: '${BUILD_NUMBER}.jpg' ) I do not want to use "attachmentsPattern" , that comes as an attachment, I tried

Jenkins pipeline - parallel stages merging only at the last stage

主宰稳场 提交于 2019-12-08 08:45:38
问题 I tried looking at the Jenkins pipeline documentation and more importantly the issue JENKINS-38442 before asking this question. I would like to create a pipeline that looks like this: Basically, I would like the parallel stages to merge at different stages rather than the next stage itself. Is this possible? The best I could do so far is only this: Below is the pipeline code that generated the above pipeline: node { def staticTests = [:] staticTests["unit tests"] = {stage('unit'){ }}

Multibranch Pipeline job scan cannot remove files

∥☆過路亽.° 提交于 2019-12-08 08:31:30
We are using Multibranch Pipeline job on Jenkins. It scans branches on master and if there are changes then build is triggered on one of the slaves. However, sometimes during the scan, we receive an exception: java.io.IOException: Unable to delete '/var/lib/jenkins/jobs/sample.job.build/branches/feature-P.of17kqq8ojl6.-PFT-repo'. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts. at hudson.Util.deleteRecursive(Util.java:352) at hudson.model.AbstractItem.performDelete(AbstractItem.java:691) at org.jenkinsci.plugins.workflow.job.WorkflowJob.performDelete(WorkflowJob.java:642) at

Jenkinsfile - agent matching multiple labels

放肆的年华 提交于 2019-12-08 08:07:40
问题 In my declarative pipeline, i need to select a node matching 2 labels. I tried something like this agent { label 'label1 && label2'} But i get an error that there are no nodes . I have a node with 2 labels label1 and label2 associated. Started by user admin Running in Durability level: MAX_SURVIVABILITY [Pipeline] node Still waiting to schedule task There are no nodes with the label ‘label1&&label2’ I know that i could temportailiy fix this by creating a 3rd label label1-2 and associate it

Jenkins 2 - How to get user role (Role Strategy Plugin) from Jenkins Workflow - Pipeline Plugin

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 06:58:37
问题 I would like to access the user role/roles, configured in Role Strategy Plugin in a Jenkins 2 pipeline (workflow): node { // Get the user Role } 回答1: import jenkins.model.Jenkins import com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy import com.michelin.cio.hudson.plugins.rolestrategy.Role node { stage('Get Role') { def user = Jenkins.getInstance().getUser( Jenkins.getInstance().getItemByFullName(env.JOB_BASE_NAME, Job.class).getBuildByNumber(env.BUILD_ID as int)

embed image in email body jenkins pipeline

早过忘川 提交于 2019-12-08 06:44:39
问题 I need to add an image in email as email body not as attachment, from Jenkins via pipeline. I am using emailext plugin in Jenkins pipeline, below is the code I am using. emailext ( subject: "test email", body: """ <html> <body> <p>please find attached score: Job '${env.JOB_NAME}':</p> <p> The last commit was by ${last_commit_user} </p> <p>Please check jenkins console at "</p> <p> For detailed report on this analysis, visit "</p> </body> </html> """, to: email_recipients, attachmentsPattern: '