jenkins-pipeline

How to I get the url of build triggered with build step on Jenkins?

ぐ巨炮叔叔 提交于 2019-11-29 05:09:14
While using Groovy based pipelines in Jenkins you can trigger child jobs using the the build stage . Still the documentation above states nothing regarding what kind of return object you would get and what attributes it has. The only thing I found so far is that I can use build.getResult() to obtain the result of the triggered job. Still, I do want to obtain the URL of this job. From the documentation for the build step in /pipeline-syntax ( waitFormCompletion argument, the original has better formatting): You may ask that this Pipeline build wait for completion of the downstream build. In

Set the build name and description from a Jenkins Declarative Pipeline

天涯浪子 提交于 2019-11-29 04:57:30
问题 I would like to set the build name and description from a Jenkins Declarative Pipeline, but can't find the proper way of doing it. I tried using an environment bracket after the pipeline, using a node bracket in an agent bracket, etc. I always get syntax error. The last version of my Jenkinsfile goes like so: pipeline { stages { stage("Build") { steps { echo "Building application..." bat "%ANT_HOME%/bin/ant.bat clean compile" currentBuild.name = "MY_VERSION_NUMBER" currentBuild.description =

Execute SonarQube Scanner within Jenkins 2 Pipeline

送分小仙女□ 提交于 2019-11-29 04:55:15
I want to execute a "SonarQube Scanner" Step within my Jenkins 2.x Pipeline. When I try to create a sample groovy within the pipeline-syntax I only get a groovy script of the following format: step <object of type hudson.plugins.sonar.SonarRunnerBuilder> Does anyone know what is the correct Step Syntax? E.g. Publish JUnit Report looks like step([$class: 'JUnitResultArchiver', testResults: '']) I use the following Versions: Jenkins 2.11 SonarQube Scanner 2.6.1 SonarQube Plugin 2.4.1 I think I got it. First you have to retrieve your SonarQube Scanner Tool def sonarqubeScannerHome = tool name:

Jenkinsfile - Conditional stage execution in the Script Pipeline syntax

浪子不回头ぞ 提交于 2019-11-29 04:01:07
问题 We are using the Script Pipeline syntax for our Jenkinsfile which has a lot of stage defined to build and deploy our code. We have a use case where I want to run all my stages if I am doing a Full Build but only run one specific stage if I need to perform some AWS routing. I know I can use the if(<expression>) to skip a stage or run a stage. Problem is I don't want to apply that if condition to every stage in my Jenkinsfile . In the new Declarative Pipeline syntax this is easily possible

How to get the changes since the last successful build in jenkins pipeline?

我是研究僧i 提交于 2019-11-29 03:48:55
Anyone have a Jenkins Pipeline script that can stuff all the changes since the previous successful build in a variable? I'm using git and a multibranch pipeline job. Well I managed to cobble something together. I'm pretty sure I you can iterate the arrays better but here's what I've got for now: node('Android') { passedBuilds = [] lastSuccessfulBuild(passedBuilds, currentBuild); def changeLog = getChangeLog(passedBuilds) echo "changeLog ${changeLog}" } def lastSuccessfulBuild(passedBuilds, build) { if ((build != null) && (build.result != 'SUCCESS')) { passedBuilds.add(build)

How to fix NotSerializableException error during Jenkins workflow build?

≡放荡痞女 提交于 2019-11-29 03:23:51
When I run the following code on the Jenkins workflow (Jenkins 1.609.1 ,workflow 1.8) I get error of 'NotSerializableException' (also below). However, if I move the "build job" outside the "for" scope it works fine (the job is activated). Any ideas why this behavior? node('master') { ws('/opt/test) { def file = "/ot.property" def line = readFile (file) def resultList = line.tokenize() for(item in resultList ) { build job: 'testjob_1' } } } Got error: Running: End of Workflow java.io.NotSerializableException: java.util.ArrayList$Itr at org.jboss.marshalling.river.RiverMarshaller.doWriteObject

Strange variable scoping behavior in Jenkinsfile

帅比萌擦擦* 提交于 2019-11-29 03:07:54
问题 When I run the below Jenkins pipeline script: def some_var = "some value" def pr() { def another_var = "another " + some_var echo "${another_var}" } pipeline { agent any stages { stage ("Run") { steps { pr() } } } } I get this error: groovy.lang.MissingPropertyException: No such property: some_var for class: groovy.lang.Binding If the def is removed from some_var , it works fine. Could someone explain the scoping rules that cause this behavior? 回答1: TL;DR variables defined with def in the

Ignore failure in pipeline build step

橙三吉。 提交于 2019-11-29 02:55:40
With jenkins build flow plugin this was possible: ignore(FAILURE){ build( "system-check-flow" ) } How to do this with Declarative Pipeline syntax? To ignore a failed step in declarative pipeline you basically have two options: Use script step and try-catch block (similar to previous proposition by R_K but in declarative style) stage('someStage') { steps { script { try { build job: 'system-check-flow' } catch (err) { echo err } } echo currentBuild.result } } Use catchError stage('someStage') { steps { catchError { build job: 'system-check-flow' } echo currentBuild.result } } In both cases the

How do I get the SCM URL inside a Jenkins Pipeline or Multibranch Pipeline?

混江龙づ霸主 提交于 2019-11-29 01:45:21
I am trying to get a prebuild merge to work inside a multibranch pipeline and I would like to avoid having to hardcode the git url in my pipeline script. It seems like scm step must store the url somehow, but I cannot figure out how to access it. You are correct, the scm object does have the information you need. When using git as the source control in a Pipeline project (or Multibranch Pipeline project), the scm global variable will be an instance of GitSCM . That means that `scm.getUserRemoteConfigs()' will return a list of UserRemoteConfig instances. Those instances have the git remote's

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

寵の児 提交于 2019-11-29 01:21:00
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 ''' # Run unit tests without capturing stdout or logs, generates cobetura reports cd ./python