jenkins-pipeline

How to access parameters in a Parameterized Build?

旧城冷巷雨未停 提交于 2019-11-26 09:41:10
问题 How do you access parameters set in the \"This build is parameterized\" section of a \"Workflow\" Jenkins job? TEST CASE Create a WORKFLOW job. Enable \"This build is parameterized\". Add a STRING PARAMETER foo with default value bar text . Add the code below to Workflow Script : node() { print \"DEBUG: parameter foo = ${env.foo}\" } Run job. RESULT DEBUG: parameter foo = null 回答1: I think the variable is available directly, rather than through env, when using Workflow plugin. Try: node() {

Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

一曲冷凌霜 提交于 2019-11-26 08:12:17
问题 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

Is it possible to capture the stdout from the sh DSL command in the pipeline

南楼画角 提交于 2019-11-26 08:10:11
问题 For example: var output=sh \"echo foo\"; echo \"output=$output\"; I will get: output=0 So, apparently I get the exit code rather than the stdout. Is it possible to capture the stdout into a pipeline variable, such that I could get: output=foo as my result? 回答1: Note: The linked Jenkins issue has since been solved. As mention in JENKINS-26133 it was not possible to get shell output as a variable. As a workaround suggested using of writ-read from temporary file. So, your example would have

How do you load a groovy file and execute it

自闭症网瘾萝莉.ら 提交于 2019-11-26 08:08:23
问题 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() 回答1: If your Jenkinsfile and groovy file in one repository and Jenkinsfile is loaded from SCM you have to do: Example.Groovy def exampleMethod() { //do

Jenkins CI Pipeline Scripts not permitted to use method groovy.lang.GroovyObject

谁说我不能喝 提交于 2019-11-26 02:37:12
问题 I am Using Jenkins 2 for compiling Java Projects, I want to read the version from a pom.xml, I was following this example: https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md The example suggest: It seems that there is some security problem accessing the File System but I can\'t figure out what it is giving (or why) that problem: I am just doing a little bit different than the example: def version() { String path = pwd(); def matcher = readFile(\"${path}/pom.xml\") =~ \'