jenkins-pipeline

println in “call” method of “vars/foo.groovy” works, but not in method in class

匆匆过客 提交于 2019-11-28 01:56:28
I'm iterating through building a Jenkins pipeline shared library, so my Jenkinsfile is a little cleaner. I'm using the following page for guidance: https://jenkins.io/doc/book/pipeline/shared-libraries/ . I first defined several methods in individual files, like " vars/methodName.groovy ", with a " call() " method in the code. This works ok, and I particularly note that " println " calls in these methods are seen in the Jenkins console output. I then decided I wanted to save some state between method calls, so I added a new file in " vars " named " uslutils.groovy " that begins like this

Pipeline jobs - pass parameters upstream?

北战南征 提交于 2019-11-28 01:09:42
问题 TL;DR: Obviously in a Jenkins pipeline job you can easily pass parameters downstream. What I want to know is if you can pass them upstream . Use case: We have three jobs; job_one , job_two , and job_three . These are frequently run separately as only one stage is needed, but in increasingly more-frequent cases we'd like to be able to run all three back to back. The first and second rely on parameters you can define ahead of time, but the third needs a parameter that is generated from the

Jenkins Pipeline Multiconfiguration Project

六月ゝ 毕业季﹏ 提交于 2019-11-28 00:55:51
问题 Original situation: I have a job in Jenkins that is running an ant script. I easily managed to test this ant script on more then one software version using a "Multi-configuration project". This type of project is really cool because it allows me to specify all the versions of the two software that I need (in my case Java and Matlab) an it will run my ant script with all the combinations of my parameters. Those parameters are then used as string to be concatenated in the definition of the

jenkins notifying error occured in different steps by sending mail in Pipeline (former known as Workflow)

一世执手 提交于 2019-11-28 00:17:06
I have a pipeline with multiple steps, for example: stage 'dev - compile' node('master') { //do something } stage 'test- compile' node('master') { //do something } stage 'prod- compile' node('master') { //do something } I want to send a email if something goes wrong in the job, how can I send an email no matter where the error got triggered, something like: try { /** all the code above **/ } catch(Exception e) { mail the error } I think it is a better way to use the jenkins build in post section instead of using try catch: pipeline { agent any stages { stage('whatever') { steps { ... } } }

Jenkins pipeline sh does not seem to respect pipe in shell command

一曲冷凌霜 提交于 2019-11-27 23:43:47
问题 I am using a Jenkinsfile in a pipeline on version 2.32.2. For various reasons I want to extract the version string from the pom. I was hoping I wouldn't have to add the maven help plugin and use evaluate. I quickly came up with a little sed expression to get it out of the pom which uses pipes and works on the commandline in the jenkins workspace on the executor. $ sed -n '/<version>/,/<version/p' pom.xml | head -1 | sed 's/[[:blank:]]*<\/*version>//g' 1.0.0-SNAPSHOT It could probably be

How to pass variables from Jenkinsfile to shell command

点点圈 提交于 2019-11-27 22:55:55
I want to use a variable which I am using inside of my Jenkinsfile script, and then pass its value into a shell script execution (either as an environment variable or command line parameter). But the following Jenkinsfile : for (i in [ 'a', 'b', 'c' ]) { echo i sh 'echo "from shell i=$i"' } Gives the output: a from shell i= b from shell i= c from shell i= Desired output is something like: a from shell i=a b from shell i=b c from shell i=c Any idea how to pass the value of i to the shell scipt? Edit: Based upon Matt's answer, I now use this solution: for (i in [ 'a', 'b', 'c' ]) { echo i sh "i=

Access a Groovy variable from within shell step in Jenkins pipeline

旧巷老猫 提交于 2019-11-27 21:57:27
Using the Pipeline plugin in Jenkins 2.x , how can I access a Groovy variable that is defined somewhere at stage- or node-level from within a sh step? Simple example: node { stage('Test Stage') { some_var = 'Hello World' // this is Groovy echo some_var // printing via Groovy works sh 'echo $some_var' // printing in shell does not work } } gives the following on the Jenkins output page: [Pipeline] { [Pipeline] stage [Pipeline] { (Test Stage) [Pipeline] echo Hello World [Pipeline] sh [test] Running shell script + echo [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline]

Return parameters/results from a job(triggered by pipeline) back to the same pipeline

自古美人都是妖i 提交于 2019-11-27 21:39:01
问题 Jenkins pipeline: I have a pipeline p1 that triggers a job j1 and then job j2 . I want some parameters that are set by j1 and passed to j2 in pipeline p1 . How do I implement this functionality using Jenkins pipeline plugin? Thanks in advance 回答1: It can be done using "env". If you manage to make j1 add its information into the build's env . If j1 was a pipeline you could to env.MYKEY=MYVALUE . For a freestyle-job it should work using the EnvInject plugin (didn't try). In p1 then you will get

Jenkins pipeline - try catch for particular stage and subsequent conditional step

允我心安 提交于 2019-11-27 21:36:48
问题 I'm trying to replicate the equivalent of a conditional stage in Jenkins pipeline using a try / catch around a preceding stage, which then sets a success variable, which is used to trigger the conditional stage. It appears that a try catch block is the way to go, setting a success var to SUCCESS or FAILED, which is used as part of a when statement later (as part of the conditional stage). The code I am using is as follows: pipeline { agent any stages { try{ stage("Run unit tests"){ steps{ sh

Jenkins dynamic declarative pipeline parameters

不羁岁月 提交于 2019-11-27 21:24:27
问题 Can the parameters in a Jenkins declarative pipeline be dynamic? I want a the choice option values be populated at runtime by a function. The following code does generate a list of options, but they seem to be stale - probably generated on the first time I ran this code. If the list of AMIs changes, the choices remain the same. I want this to run every time I select build with parameters . def findAMIs() { // Find relevant AMIs based on their name def sout = new StringBuffer(), serr = new