Questions tagged [jenkins-groovy]

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

2809 questions
10
votes
1 answer

How to clone a github repository using Jenkins pipeline script?

I am relatively new to the CI/CD concept. I am trying to clone a Github repository using declarative pipeline in Jenkins (without SCM). If i do it without any credentials then I can see in the console output that Jenkins is already trying to clone…
10
votes
1 answer

Jenkins.instance.getItem fails for jobs in folders

I can use Jenkins.instance.getItem('job_name') to access a job by name, either in the script console or in a Jenkinsfile. But I am not able to do it for multibranch pipelines or any other job that's in a folder. If I try using the project's full…
PortMan
  • 4,205
  • 9
  • 35
  • 61
10
votes
5 answers

How to read Jenkins credentials at Folder level

I am trying to migrate credentials from Jenkins to another credentials store. I want to read the credentials from the Jenkins store, and have found this script…
Banoona
  • 1,470
  • 3
  • 18
  • 32
10
votes
2 answers

Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods write java.io.File java.lang.String

I'm trying to create vault-deployment using Jenkins. Here's a link to my repo. When running the script I'm getting "Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods write java.io.File java.lang.String.…
10
votes
1 answer

Jenkins shared library fails to find SQL driver

This is a new class in a shared library for Jenkins. The shared library is loaded via the standard method under Manage Jenkins > Configure System package com.mycorp.core; @Grab(group='com.microsoft.sqlserver', module='mssql-jdbc',…
gnuchu
  • 1,496
  • 13
  • 21
10
votes
1 answer

Capture exit code from bash scripts in jenkins groovy scripts

Executing a bash script copy_file.sh from Jenkins Groovy script and trying to shoot mail depending upon the exit code generated form the bash script. copy_file.sh: #!/bin/bash $dir_1=/some/path $dir_2=/some/other/path if [ ! -d $dir ]; then echo…
Foobar-naut
  • 123
  • 1
  • 1
  • 9
10
votes
2 answers

Using a groovy class in other jenkins groovy scripts

I have 4 groovy scripts (2 are dsl.groovy scripts): JobConfig.groovy: class JobConfig { final name JobConfig(map) { name = map['name'] } } topLevel.groovy: import JobConfig.* def doSmthWithJobConfig(final JobConfig config) { …
despot
  • 7,167
  • 9
  • 44
  • 63
9
votes
2 answers

Groovy string interpolation in jenkins pipeline - mixing credentials and constants

Struggling with a part of my jenkinsfile which requires mixed credentials and defined variables passed into a function. Function looks like this: platformList.each { platform -> stage("Build ${platform}") { …
Stephen Wright
  • 2,908
  • 4
  • 19
  • 28
9
votes
1 answer

Jenkins interpretation of multiple object declarations on one line

This isn't a question, but rather a cautionary tale: I tried to save some space and declared my variables in Jenkins Declarative pipeline like so: int a, b, c Then, I initialized them as: a = b = c = 0 In my code, I use these integers as counters…
Sparkle
  • 681
  • 5
  • 10
9
votes
1 answer

Jenkins Pipeline bat multiple lines

According to the docs, one can have multiple lines in the script paramater of bat. However, I've tried the following in my stage steps and only the first line gets executed. Declarative pipeline: ... bat """ c:\\path\\to\\conda activate my_env …
Griffin
  • 13,184
  • 4
  • 29
  • 43
9
votes
3 answers

How to import a class from a Jenkins Shared Library into the pipeline

I was using some global methods in the /var directory of the shared library, and everything worked fine. Now I need to keep the state of the process, so I'm writting a groovy class. Basically I have a class called 'ClassTest.groovy' in '/src' which…
cauchi
  • 1,463
  • 2
  • 17
  • 45
8
votes
1 answer

How to assign an array to a Env variable in Jenkinsfile

I am trying to run a pipeline that has several servers. I want to do some actions in several servers at a time when selecting a choice parameter. My idea is to select a choice parameter 'APPLICATION' and execute some actions on 4 different servers…
Dieguin
  • 83
  • 1
  • 3
8
votes
2 answers

Using a dockerfile with Jenkins Scripted Pipeline Syntax

Using Jenkins Declarative Pipeline, one can easily specify a Dockerfile, agent label, build args and run args as follows: Jenkinsfile (Declarative Pipeline) agent { dockerfile { dir './path/to/dockerfile' label 'my-label' …
8
votes
3 answers

How to specify depth in checkout(scm) in scripted pipeline

our project repo is very big (2.5GB). Hence upon checkout(scm) step in the scripted pipeline, the code takes longer time to clone from GIT. and We are facing the below errors, due to GIT trying to fetch the entire history. I have tried so far with…
murthi
  • 175
  • 1
  • 4
  • 18
8
votes
1 answer

Upload file in Jenkins input step to workspace

I would like to use the "input step" of Jenkins to upload a binary file to the current workspace. However, the code below seems to upload the file to the Jenkins master, not to the workspace of the current job on the slave where the job is…
Timmy Brolin
  • 1,101
  • 1
  • 8
  • 18