jenkins-pipeline

Is it possible to create parallel Jenkins Declarative Pipeline stages in a loop?

情到浓时终转凉″ 提交于 2019-11-27 12:18:00
问题 I have a list of long running Gradle tasks on different sub projects in my project. I would like to run these in parallel using Jenkins declarative pipeline. I was hoping something like this might work: projects = [":a", ":b", ":c"] pipeline { stage("Deploy"){ parallel { for(project in projects){ stage(project ) { when { expression { someConditionalFunction(project) } } steps { sh "./gradlew ${project}:someLongrunningGradleTask" } } } } } } Needless to say that gives a compile error since it

Show a Jenkins pipeline stage as failed without failing the whole job

对着背影说爱祢 提交于 2019-11-27 12:01:37
Here's the code I'm playing with node { stage 'build' echo 'build' stage 'tests' echo 'tests' stage 'end-to-end-tests' def e2e = build job:'end-to-end-tests', propagate: false result = e2e.result if (result.equals("SUCCESS")) { stage 'deploy' build 'deploy' } else { ?????? I want to just fail this stage } } Is there any way for me to mark the 'end-to-end-tests' stage as failed without failing the whole job? Propagate false just always marks the stage as true, which is not what I want, but Propagate true marks the job as failed which I also don't want. Stage takes a block now, so wrap the stage

Executing powershell command directly in jenkins pipeline

烈酒焚心 提交于 2019-11-27 12:00:21
问题 Is it possible to call a PowerShell command directly in the pipelines groovy script? While using custom jobs in Jenkins I am able to call the command with the PowerShell Plugin. But there is no snippet to use this in the groovy script. I also tried sh() but it seems that this command does not allow multiple lines and comments inside the command. 回答1: To call a PowerShell script from the Groovy-Script: you have to use the bat command. After that, you have to be sure that the Error Code (

Jenkins Build Pipeline - Restart At Stage

早过忘川 提交于 2019-11-27 11:48:38
I have the following build pipeline set up as a job: Stage 1 - verify all dependencies exist Stage 2 - build the new jar Stage 3 - Run integration tests Stage 4 - Deploy to staging environment (manual step) Stage 5 - Deploy to production environment (manual step) I am looking for a way to start the build pipeline from a particular stage in case of a transient failure. For example, let's say there was a network issue when the user clicked to deploy to production. I don't think it makes sense to start the pipeline from stage 1... I'd like to try that step again and continue on from there in the

Using a Jenkins pipeline to checkout multiple git repos into same job

£可爱£侵袭症+ 提交于 2019-11-27 11:45:56
I'm using the Jenkins Multiple SCM plugin to check out three git repositories into three sub directories in my Jenkins job. I then execute one set of commands to build a single set of artifacts with information and code drawn from all three repositories. Multiple SCM is now depreciated, and the text recommends moving to pipelines. I tried, but I can't figure out how to make it work. Here is the directory structure I'm interested in seeing from the top level of my Jenkins job directory: $ ls Combination CombinationBuilder CombinationResults Each of those three sub-directories has a single git

How do I pass variables between stages in a declarative Jenkins pipeline?

人走茶凉 提交于 2019-11-27 11:45:32
How do I pass variables between stages in a declarative pipeline? In a scripted pipeline, I gather the procedure is to write to a temporary file, then read the file into a variable. How do I do this in a declarative pipeline? E.g. I want to trigger a build of a different job, based on a variable created by a shell action. stage("stage 1") { steps { sh "do_something > var.txt" // I want to get var.txt into VAR } } stage("stage 2") { steps { build job: "job2", parameters[string(name: "var", value: "${VAR})] } } If you want to use a file (since a script is the thing generating the value you need)

Does Jenkins Pipeline Plug-in support Docker Compose?

天涯浪子 提交于 2019-11-27 11:29:07
问题 I'm looking for a way to run Docker-enabled build consisting of multiple containers in Jenkins 2.0. Are there any plans for native support of Docker Compose in Pipeline , or through CloudBees docker plugins for pipeline. Or can/must this be addressed by explicit calls sh docker-compose... ? Maybe even use them inside try... finally to further control services lifecycle. EDIT: The first answer was to suggest a way to build docker containers in jenkins. This is not what is needed here. I

Jenkins pipeline template

懵懂的女人 提交于 2019-11-27 08:54:23
We have several Java projects. Each project has its own delivery pipeline. All pipelines have the following steps in common (simplified): Build project Release project Deploy to test environment Deploy to production environment The project pipelines only differ in project specific properties such as service names or the IP addresses of test and production environment. The questions are: How could we avoid the boilerplate that all projects have in common? Does Jenkins "Pipeline as code" provide something like pipeline templates? I could imagine that a template would save a lot of redundant code

Jenkins Pipeline / Groovy Script with undefined variables

我的梦境 提交于 2019-11-27 08:12:12
问题 I'm trying to convert my large multi-config Jenkins job over to pipeline syntax so I can, among other things, split it across multiple nodes and combine my multiple stages into one job. Here's the part where I'm seeing trouble: def build_test_configs = [:] def compilers = ['gnu', 'icc'] def configs = ['debug', 'default', 'opt'] for (int i = 0; i < configs.size(); i++) { for (int j = 0; j < compilers.size(); j++) { def node_name = "" if ("${compilers[j]}" == "gnu") { node_name = "node001" }

Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

人盡茶涼 提交于 2019-11-27 07:03:09
Solved : Thanks to below answer from S.Richmond. I needed to unset all stored maps of the groovy.json.internal.LazyMap type which meant nullifying the variables envServers and object after use. Additional : People searching for this error might be interested to use the Jenkins pipeline step readJSON instead - find more info here . I am trying to use Jenkins Pipeline to take input from the user which is passed to the job as json string. Pipeline then parses this using the slurper and I pick out the important information. It will then use that information to run 1 job multiple times in parallel