jenkins-groovy

Jenkins Multibranch Pipeline fails because it runs in Groovy Sandbox

*爱你&永不变心* 提交于 2019-12-01 17:45:36
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(SandboxInterceptor.java:130) Script Security Plugin is installed and the In-process Script Approval

Strange variable scoping behavior in Jenkinsfile

房东的猫 提交于 2019-11-30 08:59:49
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? TL;DR variables defined with def in the main script body cannot be accessed from other methods. variables defined without def can be accessed directly

How to create methods in Jenkins Declarative pipeline?

感情迁移 提交于 2019-11-29 23:53:08
In Jenkins scripted pipeline we are able to create methods and can call them. Is it possible also in the Jenkins declarative pipeline? And how? Newer versions of the declarative pipelines support this, while this was not possible before (~mid 2017). You can just declare functions as you'd expect it from a groovy script: pipeline { agent any stages { stage('Test') { steps { whateverFunction() } } } } void whateverFunction() { sh 'ls /' } You can create a groovy function like this and save it in your git which should be configured as managed library (Configure it in jenkins too): /path/to/repo

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

How to create methods in Jenkins Declarative pipeline?

前提是你 提交于 2019-11-28 20:54:15
问题 In Jenkins scripted pipeline we are able to create methods and can call them. Is it possible also in the Jenkins declarative pipeline? And how? 回答1: Newer versions of the declarative pipelines support this, while this was not possible before (~mid 2017). You can just declare functions as you'd expect it from a groovy script: pipeline { agent any stages { stage('Test') { steps { whateverFunction() } } } } void whateverFunction() { sh 'ls /' } 回答2: You can create a groovy function like this and