Questions tagged [jenkins-groovy]

Question regarding using groovy code in Jenkins, specifically in Jenkinsfile and groovy plugins

2809 questions
8
votes
1 answer

Is it possible to set environment variables on a groovy function

I know I can have an environment section on jenkins pipeline (declarative) for a stage. Like this: stage('Name') { environment { NAME = value } steps { script { Do something using these env vars } …
hagits
  • 359
  • 1
  • 3
  • 8
8
votes
2 answers

Jenkins pipeline script to copy or move file to another destination

I am preparing a Jenkins pipeline script in Groovy language. I would like to move all files and folders to another location. As Groovy supports Java so I used below java code to perform the operation. pipeline{ agent any stages{ …
mnu-nasir
  • 1,642
  • 5
  • 30
  • 62
8
votes
1 answer

Throttle parallel step in Jenkins pipeline script

I'm using something like this to run tests in parallel: stage('Test') { steps { script { testing_closures = [one: { print("staring one"); sleep 10; print("finishing one") }, two: { print("staring two"); sleep…
7
votes
1 answer

difference between echo and println in Jenkinsfile

While writing pipelines in Jenkins using Groovy, we can interchangeably use echo and println statements. Is there any difference between these statements? For example, buildNumber = "1.10"; echo "BUILD #${buildNumber}"; println "BUILD…
7
votes
3 answers

How can I use Jenkins Sidebar Link Plugin in pipeline step?

I'm working on this plugin https://plugins.jenkins.io/sidebar-link/ to add a link in jenkins side bar. This plugin works with jenkins project configuration. Now I'm trying to add a pipeline step to call this plugin. I already try lines of code below…
7
votes
2 answers

How can I create parallel stages in Jenkins scripted pipeline?

I am trying to implement parallelization in my Jenkins pipeline code where I can run two stages in parallel. I know this is possible in declarative pipeline, but I am using scripted pipeline. I've attempted to implement this by doing something like…
7
votes
1 answer

Jenkins Pipeline sshPublisher: How to get exit code and output of execCommand?

Using Jenkins Pipeline's sshPublisher plugin ("publish over ssh"), is it possible to get the exit code and output of the command ran with execCommand (after artifacts have been transferred over)? I'm using the plugin as follows: script { echo…
Katie
  • 45,622
  • 19
  • 93
  • 125
7
votes
3 answers

How can I add git clone operation in inline groovy script

I want to clone repo using inline groovy script in jenkins. How can I execute git clone and build the app using groovy.
7
votes
1 answer

Jenkins Shared Libraries: is it possible to pass arguments to shell scripts imported as 'libraryResource'?

I have the following setup: (Stripped out) Jenkinsfile: @Library('my-custom-library') _ pipeline { agent any stages { stage('Example') { steps { printHello name: 'Jenkins' } } …
ebu_sho
  • 394
  • 6
  • 17
7
votes
2 answers

Building project with Active Choice Reactive Reference Parameter

I'm new to jenkins and groovy and I'm trying to create my own configuration which allows me to build my project with various parameters. To achieve that I use Active Choices Reactive Reference Parameter. As a Choice Type I set "Formatted HTML". It…
jb27
  • 93
  • 1
  • 1
  • 7
7
votes
2 answers

How to get Jenkins build job duration

Is it possible to get Jenkins build duration using scripts or using some inbuilt functionality. I tried with ${BUILD_DURATION} but it didn't work. Can anyone please suggest?
7
votes
1 answer

Combining multiple collectEntries in Groovy and Jenkins Pipeline

I am trying to use multiple collectEntries in series in my Groovy script. Its better to see the code, right now I've got: stage('Test') { // Reading content of the file def portsFileContent = readFile 'UsedPorts.txt' …
rm -rf
  • 968
  • 1
  • 12
  • 28
6
votes
1 answer

Jenkins Groovy unix Script Error java.lang.NoSuchMethodError: 'boolean mightBePositionalArgumentConstructor VariableExpression

I am trying to to create Jenkins pipeline and have the below line which I copied from existing working pipeline in the same Jenkins instance. script { def GitDValue = sh ( script: "pwd", …
ViratKohli
  • 333
  • 1
  • 3
  • 16
6
votes
3 answers

Why does Jenkins creates a subfolder within the workspace@script folder to checkout git code instead of the workspace@script itself?

This happened after I updated some plugins and added 'blue ocean' to our Jenkins. Every job we have is using a JenkinsFile to build and package our applications. But we are loading some groovy files within our git from the workspace@script folder,…
WannaGetHigh
  • 3,826
  • 4
  • 23
  • 31
6
votes
2 answers

Condition in Jenkins pipeline on the triggers directive

Jenkins has a nice relatively comprehensive documentation about Jenkinsfile syntax. But I still not find there an answer is it possible to do a flow control on the top level of pipeline? Literally include something if just in pipeline {} section…