jenkins-groovy

Jenkins generate new parameters based on another parameter value

泄露秘密 提交于 2021-02-17 05:01:31
问题 I have a choice parameter called 'Data Center' which has two values DC01 and DC02. If user chooses DC01 I want few other build parameters to show up, if he chooses DC02 I want other parameters to show up. Is there any way to do it? If user chooses DC01, I want two more fields such as 'hostname' and 'IP address' which are just text fields. I have tried using Active Choice Plugin, but I don't think we can generate text field parameters using that. Can anyone help? 回答1: We can generate text

Jenkins generate new parameters based on another parameter value

给你一囗甜甜゛ 提交于 2021-02-17 05:01:22
问题 I have a choice parameter called 'Data Center' which has two values DC01 and DC02. If user chooses DC01 I want few other build parameters to show up, if he chooses DC02 I want other parameters to show up. Is there any way to do it? If user chooses DC01, I want two more fields such as 'hostname' and 'IP address' which are just text fields. I have tried using Active Choice Plugin, but I don't think we can generate text field parameters using that. Can anyone help? 回答1: We can generate text

How can I male groovy on Jenkins mask the output of a variable the same way it does for credentials?

无人久伴 提交于 2021-02-17 03:59:05
问题 Is there a way in groovy on Jenkins to take an arbitrary String variable - say the result of an API call to another service - and make Jenkins mask it in console output as it does automatically for values read in from the Credentials Manager? 回答1: UPDATED SOLUTION: To hide the output of a variable you can use the Mask Password Plugin Here is an exemple: String myPassword = 'toto' node { println "my password is displayed: ${myPassword}" wrap([$class: 'MaskPasswordsBuildWrapper',

Importing class from git - unable to resolve class

馋奶兔 提交于 2021-02-15 07:52:31
问题 I am constructing a Shared Library which I want to have class definitions, such as: package com.org.pipeline.aws String family JsonObject taskDefinition class TaskDefinition { def getTaskDefinition(family) { def jsonSlurper = new groovy.json.JsonSlurper() def object = slurper.parseText( sh(returnStdout: true, script: "aws ecs describe-task-definition --task-definition ${family}" ) ) return assert object instanceof Map taskDefinition = object["taskDefinition"] } } And I am importing it via a

Jenkins:How to Achieve parallel dynamic stages in jenkins declarative pipeline

ぐ巨炮叔叔 提交于 2021-02-08 11:03:53
问题 I am working on declarative pipeline. I am trying to achieve dynamic stages which should distribute the stages parallel with the agents defined. When i explored i learned how to achieve Dynamic sequential stages. Below is my sample code. My problem now is, how to achieve parallel stages with agents i have. For example, if i have 3 agents all the 5 stages should run parallel in the agents parallel. I tried using parallel tests but not working. Please help me to improve further ! def learn

how to trigger the scheduled job which has parameters

放肆的年华 提交于 2021-01-29 12:31:06
问题 How to schedule the parameterized jenkins job? I have a parameterized parent job which has 6 child jobs. when the parent job is triggered it should start the child jobs one after another.I should run the parent job for every 7 hours on weekend which I have given as H */7 * * 6-7 . My questions are: How does the parent job takes the parameters when it is triggered? Does it take the default choice or do i need a script to give the parameters? How to configure if i want to skip any one of the

How to create and loop over an ArrayList of strings in Jenkins Groovy Pipeline

人盡茶涼 提交于 2021-01-29 10:19:08
问题 As stated in the title, I'm attempting to loop over an ArrayList of strings in a Jenkins Groovy Pipeline script (using scripted Pipeline syntax). Let me lay out the entire "problem" for you. I start with a string of filesystem locations separated by spaces: "/var/x /var/y /var/z ... " like so. I loop over this string adding each character to a temp string . And then when I reach a space, I add that temp string to the array and restart. Here's some code showing how I do this: def full_string =

Error while executing another process through Groovy script

若如初见. 提交于 2021-01-28 05:30:23
问题 I'm invoking another process through Groovy script of Jenkins pipeline. Following is simple one script - pipeline { agent {label 'xxx.xxx.xx.xx} stages { stage('Test') { steps { script { sh 'pwd' def path = "pwd".execute().text } } } } } sh 'pwd' works perfectly fine. However "pwd".execute().text results into following error - java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.<init>

Jenkinsfile windows cmd output variable reference

十年热恋 提交于 2021-01-27 23:45:30
问题 I'm pretty new to groovy.In my Jenkinsfile i am trying to store a windows cmd output in a variable, use it in the next command, but nothing seems to be working. This is the closest i got: pipeline { agent any stages { stage('package-windows') { when { expression { isUnix() == false} } steps { script { FILENAME = bat(label: 'Get file name', returnStdout: true, script:"dir \".\\archive\\%MY_FOLDER%\\www\\main.*.js\" /s /b") } bat label: 'replace content', script: "powershell -Command \"(gc \"

How to Backup Jenkins using Jenkinsfile

拈花ヽ惹草 提交于 2021-01-26 03:04:50
问题 How To do Jenkins jobs configuration backup using Jenkinsfile without plugins? things to be backup : system configuration {jenkins} jobs configuration 回答1: We were not happy with the plugins backup solutions, so we have a freestyle shell step job run on master (usually a no-no, so only allow managed special task like backup to run there) with a simple tar cmd, one for system config (xmls, keys, etc), one for jobs (excluding logs 'n stuff). System backup In ${JENKINS_HOME} , you'll want to