jenkins-pipeline

Running stages in parallel with Jenkins workflow / pipeline

醉酒当歌 提交于 2019-11-27 00:27:02
问题 Please note: the question is based on the old, now called "scripted" pipeline format. When using "declarative pipelines", parallel blocks can be nested inside of stage blocks (see Parallel stages with Declarative Pipeline 1.2). I'm wondering how parallel steps are supposed to work with Jenkins workflow/pipeline plugin, esp. how to mix them with build stages. I know about the general pattern: parallel(firstTask: { // Do some stuff }, secondTask: { // Do some other stuff in parallel }) However,

Jenkins Pipeline: “input” step blocks executor

微笑、不失礼 提交于 2019-11-27 00:14:55
问题 After going through the pipeline and Jenkinsfile documentation, I am a bit confused on how to create a Stage -> Production pipeline. One way is to use the input step like node() { stage 'Build to Stage' sh '# ...' input 'Deploy to Production' stage 'Build to Production' sh '# ...' } This seems a bit clunky, as this will block an executor all the time until you want to deploy to production. Is there any alternative way of being able to deploy to production, from Jenkins. 回答1: EDIT (Oct 2016):

Pipeline pass parameters to downstream jobs

谁说我不能喝 提交于 2019-11-27 00:08:25
问题 I'm using Jenkins v2.1 with the integrated delivery pipeline feature (https://jenkins.io/solutions/pipeline/) to orchestrate two existing builds (build and deploy). In my parameterized build I have 3 user parameters setup, which also needs to be selectable in the pipeline. The pipeline script is as follows: node: { stage 'build' build job: 'build', parameters: [[$class: 'StringParameterValue', name: 'target', value: target], [$class: 'ListSubversionTagsParameterValue', name: 'release', tag:

How to differentiate build triggers in Jenkins Pipeline

耗尽温柔 提交于 2019-11-26 23:20:25
问题 I'm hoping to add a conditional stage to my Jenkinsfile that runs depending on how the build was triggered. Currently we are set up such that builds are either triggered by: changes to our git repo that are picked up on branch indexing a user manually triggering the build using the 'build now' button in the UI. Is there any way to run different pipeline steps depending on which of these actions triggered the build? 回答1: The following code should works to determine if a user has started the

Access a Groovy variable from within shell step in Jenkins pipeline

心已入冬 提交于 2019-11-26 23:00:47
问题 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]

Can I create dynamically stages in a Jenkins pipeline?

烈酒焚心 提交于 2019-11-26 22:45:12
问题 I need to launch a dynamic set of tests in a declarative pipeline. For better visualization purposes, I'd like to create a stage for each test. Is there a way to do so? The only way to create a stage I know is: stage('foo') { ... } I've seen this example, but I it does not use declarative syntax. 回答1: Use the scripted syntax that allows more flexibility than the declarative syntax, even though the declarative is more documented and recommended. For example stages can be created in a loop: def

Extract version ID from POM in a Jenkins pipeline

六月ゝ 毕业季﹏ 提交于 2019-11-26 22:21:21
问题 I've created a pipeline and using the embedded groovy pipeline script definition and can't seem to get the version ID of the project from the POM. I tried this which works in a groovy console but on in the Jenkins build pipeline script: def project = new XmlSlurper().parse(new File("pom.xml")) def pomv = project.version.toString() According to the documentation Jenkins has a $POM_VERSION but the value doesn't have anything in it when I assign it to a variable and echo it out. def pomv = "$POM

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

蓝咒 提交于 2019-11-26 22:05:32
问题 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

How do you load a groovy file and execute it

一笑奈何 提交于 2019-11-26 21:59:10
I have a jenkinsfile dropped into the root of my project and would like to pull in a groovy file for my pipeline and execute it. The only way that I've been able to get this to work is to create a separate project and use the fileLoader.fromGit command. I would like to do def pipeline = load 'groovy-file-name.groovy' pipeline.pipeline() Anton Shishkin If your Jenkinsfile and groovy file in one repository and Jenkinsfile is loaded from SCM you have to do: Example.Groovy def exampleMethod() { //do something } def otherExampleMethod() { //do something else } return this JenkinsFile node { def

How to do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

落花浮王杯 提交于 2019-11-26 21:23:34
I have something like this on a Jenkinsfile (Groovy) and I want to record the stdout and the exit code in a variable in order to use the information later. sh "ls -l" How can I do this, especially as it seems that you cannot really run any kind of groovy code inside the Jenkinsfile ? G. Roggemans The latest version of the pipeline sh step allows you to do the following; // Git committer email GIT_COMMIT_EMAIL = sh ( script: 'git --no-pager show -s --format=\'%ae\'', returnStdout: true ).trim() echo "Git committer email: ${GIT_COMMIT_EMAIL}" Another feature is the returnStatus option. // Test