jenkins-groovy

How to pass choice parameter to call a job inside jenkins pipeline

て烟熏妆下的殇ゞ 提交于 2020-02-07 02:26:11
问题 How can I pass choice parameters for the downstream job when called inside a stage in the jenkins pipeline? I tried the below solutions but none worked: stage('build job') { steps{ script{ build job: 'test', parameters: [ choice(choices: "option1\noption2\noption3\n", description: '', name: 'choiceParam') ] } } } fails with java.lang.UnsupportedOperationException: no known implementation of class hudson.model.ParameterValue is using symbol ‘choice’ Tried these as well: parameters: [ [$class:

Using multiple JDKs in single scripted pipeline

為{幸葍}努か 提交于 2020-02-06 11:09:42
问题 We have a situation where JDK1.7 is used to compile a project and JDK1.8 is used in sonar pipeline job on the aforementioned compiled code. Is it possible to use 2 JDKs in a single scripted job. If sonar stage is reached, then JDK 1.8 must be used. Currently this is our pipeline. node('jenkins_uat_sdg_1g'){ env.JAVA_HOME="${tool 'JDK1.7_110'}" env.PATH="${env.JAVA_HOME}/bin:${env.PATH}" deleteDir() try{ try{ stage('SCM Code Checkout'){ echo "Checking out source code from SVN..." echo

Jenkins groovy - How to retrieve tag from latest commit?

半城伤御伤魂 提交于 2020-01-24 13:15:31
问题 To fetch the latest commit from branchName , we run below code: treeMapData = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git") It is ensured that there is one tag per commit, as per our workflow We want to build the code, only if the commit is tagged. How to retrieve the tag name for that latest commit? 回答1: We can fetch the tags from the repo in case Jenkins hasn't already. git fetch --tags We need to find a tag(s) which point to a

How do i compare user inputed password to credentials passphrase

空扰寡人 提交于 2020-01-13 19:04:59
问题 I have a scripted pipeline that requests the user's password using the input function and compares it with the user's saved credentials passphrase. If the user input is a type string then it works. However, when I changed the input type to password (so it isn't visible on the screen when the user types it), it fails with an assert error. I made sure to enter the password that matches the one in the credentials file. I am using Jenkins 2.83 with latest Credentials Plugin and Credentials

Create a file with some content using Groovy in Jenkins pipeline

限于喜欢 提交于 2020-01-13 07:36:09
问题 I am trying to create a file called groovy1.txt with the content "Working with files the Groovy way is easy." Note: I don't want to use the shell to create this file, instead I want to use Groovy to achieve this. I have following script in my Jenkins pipeline. node { def file1 = new File('groovy1.txt') file1.write 'Working with files the Groovy way is easy.\n' sh 'ls -l' // Expecting the file groovy1.txt should present with the content mentioned above } But it is throwing FileNotFound

Upload file in Jenkins input step to workspace

雨燕双飞 提交于 2020-01-10 03:18:05
问题 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 running. Is there any way to fix that? Preferably without having to add an executor on the master or clutter the master disk with files. def inFile = input id: 'file1', message: 'Upload a file', parameters: [file(name: 'data.tmp', description: 'Choose a

Configuring Groovy on Jenkins

≯℡__Kan透↙ 提交于 2020-01-06 06:37:29
问题 I'm using Jenkins ver 2.121.2. I'm trying to configure the Groovy plugin to run groovy scripts via a Jenkins job. The plugin documentation provided here does not appear to match the UI I see in the System Configuration - Groovy section of this version of Jenkins. The various parameters don't match and so far I'm unable to get the plugin to run a simply groovy script. Not being familar with java and how the classpath works I'm not able to loosely interpret the instructions and get it working.

invoke one Jenkinsfile of different repo to another jenkinsfile

那年仲夏 提交于 2019-12-25 03:35:32
问题 I have a Jenkinsfile-A like below, In this file,I need to invoke another Jenkinsfile-B after execution of all the stages. Jenkinsfile-A #!groovy​ pipeline { agent { label "" } triggers { pollSCM('*/5 * * * *') } stages { stage('Build Artifact') { steps { } } stage('Publish Artifact') { steps { } } }//stages post { always { deleteDir() /* clean up our workspace */ } } }//pipeline def jenkinsFile stage('Loading Jenkinsfile'){ jenkinsFile = fileLoader.fromGit('Jenkinsfile', 'git@bitbucket.org

Groovy get edit type of tfs changeset

十年热恋 提交于 2019-12-25 00:43:02
问题 I need to get tfs changeset files (I have accomplished this) and also whether it was added or deleted using the groovy plugin on jenkins server. I cannot figure out how to access the item class that holds the method to get the edit type. I have tried the below code and just cannot figure it out. import java.lang.* import jenkins.* import jenkins.model.* import hudson.* import hudson.model.* import hudson.util.* import hudson.scm.* import hudson.scm.SubversionChangeLogSet.LogEntry import

Issues with multibranch pipeline job DSL

孤街浪徒 提交于 2019-12-25 00:19:57
问题 I am having issues with multibranch pipeline for job DSL plugin to automate the creation of multibranch pipeline job. The piece am having issues with is how to let set the path to the Jenkinsfile on the repo. I have looked online for documentation but found nothing to help. I have even tried to get example scripts but multibranch job DSL scripts are rare on the internet. Matter of fact could not find any that has Jenkinsfile set in it jobs.groovy folderName = "${JENKINS_PATH}" folder