jenkins-groovy

Jenkins pipeline - How to read the success status of build?

本秂侑毒 提交于 2019-12-25 00:13:29
问题 Below is the output after running the build(with success): $ sam build 2019-06-02 15:36:37 Building resource 'SomeFunction' 2019-06-02 15:36:37 Running PythonPipBuilder:ResolveDependencies 2019-06-02 15:36:39 Running PythonPipBuilder:CopySource Build Succeeded Built Artifacts : .aws-sam/build Built Template : .aws-sam/build/template.yaml Commands you can use next ========================= [*] Invoke Function: sam local invoke [*] Package: sam package --s3-bucket <yourbucket> [command] && echo

groovy to list Jenkins jobs with GIT URL used in jobs

北城以北 提交于 2019-12-24 18:40:38
问题 We need to print Jenkins jobs URLs and GIT URL configured inside these jobs. For example: Assume my Jenkins URL is : http://localhost:8080 & my git URL is ssh://git:424 If i run groovy code from Jenkins, It should return: http://localhost:8080/job_name1 | ssh://git:424/repo_name1 (GIT URL configured in SCM section of job_name1) http://localhost:8080/job_name2 | ssh://git:424/repo_name2 (GIT URL configured in SCM section of job_name2) I have below code to list jobs : Jenkins.instance

Getting bad substitution error when bumping up version using maven versions plugin in Jenkins pipeline

不羁岁月 提交于 2019-12-24 11:37:26
问题 I get a bad substitution error when I run this command in my jenkins pipeline sh 'mvn build-helper:parse-version versions:set \ -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}-SNAPSHOT \ -DgenerateBackupPoms=false \ -DprocessAllModules \ -DgenerateBackupPoms=false' This is the error message in this case - [code] Running shell script /apps/jenkins/latest/workspace/ess-holani_master

How to set “Scan Organization Triggers” via Jenkins script console?

冷暖自知 提交于 2019-12-24 11:29:36
问题 I need a way to set “Scan Organization Triggers” via the Jenkins script console. This is close, but only shows Multibranch or Organization Scan triggers if they already exist: https://github.com/cloudbees/jenkins-scripts/blob/master/setOrgFolderIndex.groovy 回答1: Here's a script that I made that detects multibranch or organization triggers. If the project doesn't already have one, it will create a trigger. Note: the addTrigger part is commented out, so this should be safe to run as-is. import

I have a Jenkins global variable in a string - how do I evaluate it?

99封情书 提交于 2019-12-23 04:47:11
问题 I need to accept all kinds of global Jenkins variables as strings (basically as parameters to ansible like system - a template stored in \vars ). def proof = "\"${params.REPOSITORY_NAME}\"" echo proof def before = "\"\${params.REPOSITORY_NAME}\"" echo before def after = Eval.me(before) echo after The result is: [Pipeline] echo "asfd" [Pipeline] echo "${params.REPOSITORY_NAME}" groovy.lang.MissingPropertyException: No such property: params for class: Script1 the first echo proves that the

Catching multiple errors in Jenkins workflow

孤街浪徒 提交于 2019-12-21 20:22:38
问题 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

Iterating Jenkins groovy map, with multiple sets

醉酒当歌 提交于 2019-12-13 19:09:41
问题 I'd like to ask for help with a a Jenkins groovy pipeline, copied from here: Is it possible to create parallel Jenkins Declarative Pipeline stages in a loop? I'd like for a several sets of vars to be passed in a under a map, for several stages under a parallel run. However, only the last set (square brackets at the bottom of the map) gets registered for my map. When the parallel stage runs, the map iterates successfully, but only with the last set (currently install_Stage(it) ), ignoring

How to use groovy env. variable in Jenkins to pass through bat command in Jenkins pipeline

荒凉一梦 提交于 2019-12-13 16:20:30
问题 I have stage in my jenkinsfile, that executes a bat command: stage ('build'){ bat '%cd%\\MySimpleProject\\bin\\Execute.bat "${env.BRANCH_NAME}"' } My batch command requires a parameter that is the current branch in svn. When I use this: echo "SVN_BRANCH_NAME is ${env.BRANCH_NAME}" It would give the value of BRANCH_NAME but if I pass it as param to my batch file, it literally pass ${env.BRANCH_NAME} not the value. Is their a way to do this? 回答1: It's because all is wrapped in single quotes and

How to continue a stage in jenkins pipeline even if the build fails

回眸只為那壹抹淺笑 提交于 2019-12-12 22:29:36
问题 So I have a pipeline with multiple stages and with each stage there are couple of build job processes. When I run the pipeline and there is a failure in any one of the builds the stage fails and doesn't build the other builds in the stage. How can I get around this so it builds the remaining jobs in the stage? 回答1: you can use the convention try { // your build steps } finally { // always run... } 来源: https://stackoverflow.com/questions/40942178/how-to-continue-a-stage-in-jenkins-pipeline

How can you pass same parameters to different builds without redundant code in Jenkins Pipeline

牧云@^-^@ 提交于 2019-12-12 04:32:26
问题 How can you pass same parameters to different builds without redundant code in Jenkins Pipeline groovy. I don't want to repeat the parameters. node('master') { parallel( "stream 1(X)" : { stage('X') { build 'Job1', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')] } }, "stream 2 (Y)" : { stage('Y') { build 'Job2', parameters: [string(name: 'branch', value: 'trunk'), string(name: 'freq', value: 'Continuous')] } } ) } 回答1: It is pretty easy : just