jenkins-groovy

how to fix - stageResult set to FAILURE but still get success in jenkins

落爺英雄遲暮 提交于 2019-12-08 03:36:57
问题 I'm trying to create a very simple pipeline, it has one stage and one step. it uses the job 'build' I created as freestyle (which works) but I added an error (the parameter project name has a wrong value - 'test3' instead of 'test') when I ran it, it stay green and send "success" although it failed - if I enter the log I'll see this: Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace

Adding Suppress automatic scm triggering except for named branches in Jenkins Job DSL?

喜欢而已 提交于 2019-12-07 06:04:35
问题 How do I add default Suppress automatic scm triggering except for named branch - development in Job DSL? I tried docs https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob . It doesn't say much. Seems like it is not supported. So I guess my only way is adding custom properties directly to XML via configure block. What I want: <strategy class="jenkins.branch.NamedExceptionsBranchPropertyStrategy"> <defaultProperties class="java.util.Arrays$ArrayList"> <a class="jenkins.branch

How do you handle global variables in a declarative pipeline?

荒凉一梦 提交于 2019-12-06 23:19:04
问题 Previously asked a question about how to overwrite variables defined in an environment directive and it seems that's not possible. I want to set a variable in one stage and have it accessible to other stages. In a declarative pipeline it seems the only way to do this is in a script{} block. For example I need to set some vars after checkout. So at the end of the checkout stage I have a script{} block that sets those vars and they are accessible in other stages. This works, but it feels wrong.

Load properties from properties file and make them available throughout the job/pipeline - Jenkins declarative syntax

六月ゝ 毕业季﹏ 提交于 2019-12-06 07:57:09
问题 My requirement is simple, i just want to externalize some 'values' to make my Jenkinsfile more re usable and for this i need to load the properties from a file which is going to be right next to Jenkinsfile, and make sure that these properties are available anywhere in the pipeline. I am still new to groovy and Jenkins code but never thought such a simple thing would be so difficult. I enabled some methods in script security plugin but the following code (and several variations i tried around

how to fix - stageResult set to FAILURE but still get success in jenkins

时间秒杀一切 提交于 2019-12-06 07:38:42
I'm trying to create a very simple pipeline, it has one stage and one step. it uses the job 'build' I created as freestyle (which works) but I added an error (the parameter project name has a wrong value - 'test3' instead of 'test') when I ran it, it stay green and send "success" although it failed - if I enter the log I'll see this: Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\pipeline testing [Pipeline] { [Pipeline] stage [Pipeline] { (1) [Pipeline] catchError [Pipeline] { [Pipeline]

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

前提是你 提交于 2019-12-05 16:41:39
问题 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

How do you handle global variables in a declarative pipeline?

淺唱寂寞╮ 提交于 2019-12-05 04:27:47
Previously asked a question about how to overwrite variables defined in an environment directive and it seems that's not possible. I want to set a variable in one stage and have it accessible to other stages. In a declarative pipeline it seems the only way to do this is in a script{} block. For example I need to set some vars after checkout. So at the end of the checkout stage I have a script{} block that sets those vars and they are accessible in other stages. This works, but it feels wrong. And for the sake of readability I'd much prefer to declare these variables at the top of the pipeline

Catching multiple errors in Jenkins workflow

守給你的承諾、 提交于 2019-12-04 13:09:07
My workflow sends mails when it fails using a try-catch. i have also enable concurrency and with this, when multiple jobs of the same workflow enters into a throttling stage, the new ones cancels the older ones. This throw an exception of "org.jenkinsci.plugins.workflow.steps.FlowInterruptedException" And canceled jobs also triggers the mail notification. Now i have modified my workflow to catch the specific FlowInterruptedException exception and suppress the mail notice and let anything else to trigger the mail, like so. node { try { // some stages for the workflow } catch (org.jenkinsci

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

Jenkins Multibranch Pipeline fails because it runs in Groovy Sandbox

百般思念 提交于 2019-12-01 17:55:50
问题 My Jenkins CI/CD build configuration was working and nothing changed until my last pull request and I need to get this working again. The Multibranch Pipeline is configured to run a jenkinsfile from BitBucket SCM but this is now failing with the following error; groovy.lang.MissingPropertyException: No such property: pipeline for class: groovy.lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall