jenkins-pipeline

Set a stage status in Jenkins Pipelines

人盡茶涼 提交于 2019-12-04 03:56:41
Is there any way in a scripted pipeline to mark a stage as unstable but only show that stage as unstable without marking every stage as unstable in the output? I can do something like this: node() { stage("Stage1") { // do work (passes) } stage("Stage2") { // something went wrong, but it isn't catastrophic... currentBuild.result = 'UNSTABLE' } stage("Stage3") { // keep going... } } But when I run this, Jenkins marks everything as unstable... but I'd like the first and last stages to show green if possible and just the stage that had an issue to go yellow. It's ok if the whole pipeline gets

How to get username password stored in Jenkins credentials separately in jenkinsfile

一曲冷凌霜 提交于 2019-12-04 03:55:17
I've stored username and password as credentials in jenkins. Now I would like to use them in my Jenkinsfile. I am using withCredentials DSL, however, I'm not sure how to get the username password as separate variables so I can use them in my command. This is what I'm doing: withCredentials([usernameColonPassword(credentialsId: 'mycreds', variable: 'MYCREDS')]) { sh 'cf login some.awesome.url -u <user> -p password' } How can I the username and passwork separately? I tried doing ${MYCREDS.split(":")[0]} but that doesn't seem to work. You can use the UsernamePasswordMultiBinding to get credential

How to clear workspace in Jenkins pipeline before job starts

痞子三分冷 提交于 2019-12-04 03:47:09
I need to clear workspace before build starts. I tried using cleanDir() in stages, but in the declarative pipeline, check out happens first and when stage with cleadDir runs, checked out code also gets cleared which is not desired. How can we clear the workspace before check out in the declarative pipeline? Use the means of your VCS, with Git run git clean -fdx Actually, I have to revise my answer based on recent changes to the pipeline plugins, e.g. GitHub Branch Source Plugin 2.2.0 with JENKINS-43507 . Besides the different branch discovery behaviours, which can be configured, one can now

How to get stdout and stderr from single Jenkins Pipeline parallel blocks?

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:33:47
问题 I'm using a parallel block into my Jenkinsfile to execute concurrently some tests, but all the outputs are getting mixed up. This is an extract of my Jenkinsfile, as an example: // do some IT against different databases stage name: 'IT' parallel ( mysqlIT: { node { executeMysqlIT() } }, oracleIT: { node { executeOracleIT() } } ) Please note that, as suggested here I'm running a new node within each parallel , so they get properly parallelized and each of them gets its own workspace. What

Permission Denied while trying to connect to Docker Daemon while running Jenkins pipeline in Macbook

可紊 提交于 2019-12-04 03:27:00
问题 I am trying to run Jenkins pipeline job in my macbook. I also have docker instance running locally. Initially I got the " docker command not found " error while running the Jenkins Job. I fixed the error by adding a symlink " ln -f -s /Applications/Docker.app/Contents/Resources/bin/* /usr/local/bin " I also applied these two changes so that jenkins user has the access to the docker directory chmod -R 777 /Users/myUserName/Library/Containers/com.docker.docker/ chmod -R 777 /Users/myUserName

installing node on jenkins 2.0 using the pipeline plugin

牧云@^-^@ 提交于 2019-12-04 03:09:39
I am running the following docker image jenkinsci/jenkins:2.0-rc-1 to try out jenkins 2.0, and the "pipeline" view. I can't seem to install node. Here's my pipeline script: node { //tool([name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation']) sh 'echo $(whoami)' sh 'node -v' } The response when this runs is: [ci] Running shell script + whoami + echo jenkins jenkins [Pipeline] sh [ci] Running shell script + node -v /../durable-3b0b1b07/script.sh: 2: /../durable-3b0b1b07/script.sh: node: not found Here's what i've tried: the jenkins NodeJS tool (which works correctly when

How to get a list of all Jenkins nodes assigned with label including master node?

萝らか妹 提交于 2019-12-04 01:55:46
I'm creating a Jenkins pipeline job and I need to run a job on all nodes labelled with a certain label. Therefore I'm trying to get a list of node names assigned with a certain label. (With a node I can get the labels with getAssignedLabels() ) The nodes -list in jenkins.model.Jenkins.instance.nodes seems not contain the master-node which I need to include in my search. My current solution is to iterate over the jenkins.model.Jenkins.instance.computers and use the getNode() -method to get the node. This works, but in the javadoc of Jenkins I'm reading the this list might not be up-to-date. In

write yaml file in jenkins with groovy

こ雲淡風輕ζ 提交于 2019-12-04 01:26:24
What is the best way to write/modify a *.yaml file in Groovy? I would like to modify the version maintained in a yaml file within my jenkins pipeline job. With readYaml I can get the content, but how can I write it back again? One way that comes to my mind would be to do a sed on the file. But I think thats not very accurate. Randy The Pipeline Utility Steps plugin has the readYaml and writeYaml steps to interact with YAML files. writeYaml will not overwrite your file by default so you have to remove it first. def filename = 'values.yaml' def data = readYaml file: filename // Change something

Error: “Expected named arguments” in parallel in Jenkins groovy script

…衆ロ難τιáo~ 提交于 2019-12-04 00:49:51
I have a Jenkins 2.0 pipeline, with a groovyscript like this: node('nnh561.raijin') { stage 'checkout' build('trunk/checkout') stage 'build' parallel( { build('trunk/build/gfortran') }, { build('trunk/build/ifort') } ) } Each of the individual jobs builds fine, but when I try to run the pipeline, it spits out this error when it hits the parallel step: java.lang.IllegalArgumentException: Expected named arguments but got [org.jenkinsci.plugins.workflow.cps.CpsClosure2@242d0d3a, org.jenkinsci.plugins.workflow.cps.CpsClosure2@9bf6d64] at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java

Getting current timestamp in inline pipeline script using pipeline plugin of hudson

自古美人都是妖i 提交于 2019-12-04 00:25:18
I want to get Getting current timestamp in inline pipeline script using pipeline plugin of hudson. For setting up build display name. Inline groovy script used: def jobName = env.JOB_NAME + "_" + new Date() currentBuild.displayName = "$jobName" node { echo "job name $jobName" } Error on console : org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.util.Date Jenkins scripts are running in a sandbox, by default the Groovy script doesn't have permissions for some operations. When you perform an operation without permissions the