jenkins-pipeline

Jenkins: pipeline script - call plugin

删除回忆录丶 提交于 2019-12-10 10:07:15
问题 I am writing an Jenkins pipeline script and try to call a plugin what is in a normal job configuration configured under "build". Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Parameter+Pool+Plugin I tried calling it via: step([$class: 'ParameterPool', projects: '123', name: 'ID', values: '1, 2, 3, ']) But its not working. Calling other plugins like: step([$class: 'LogParserPublisher', parsingRulesPath: '/opt/log_minimal_parser', useProjectRule: false]) works just fine. How I can call a

Jenkins Pipeline - How do I use the 'tool' option to specify a custom tool?

主宰稳场 提交于 2019-12-10 09:45:26
问题 I have a custom tool defined within Jenkins via the Custom Tools plugin. If I create a freestyle project the Install custom tools option correctly finds and uses the tool (Salesforce DX) during execution. However, I cannot find a way to do the same via a pipeline file. I have used the pipeline syntax snippet generator to get: tool name: 'sfdx', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool' I have put that into my stage definition: stage('FetchMetadata') { print 'Collect Prod

How to call java function in Jenkinsfile using Pipeline plugin in Jenkins

梦想与她 提交于 2019-12-10 09:34:01
问题 I am using pipeline plugin in jenkins. My Jenkinsfile has numToEcho =1,2,3,4 but I want to call Test.myNumbers() to get list of values. How can I call myNumbers() java function in Jenkinsfile? Or do I need to have a separate groovy script file and that file I should place inside java jar which has Test class? My Jenkinsfile: def numToEcho = [1,2,3,4] def stepsForParallel = [:] for (int i = 0; i < numToEcho.size(); i++) { def s = numToEcho.get(i) def stepName = "echoing ${s}" stepsForParallel

How to access git branch name from pipeline job?

拥有回忆 提交于 2019-12-10 03:50:13
问题 I have a Jenkins Pipeline job which is configured to checkout a git repo and a specific local branch. How can i get the name of the local branch in my Jenkinsfile? I tried to load the git jenkins plugin env properties but had no luck. node { checkout scm echo "1 "+ env.GIT_LOCAL_BRANCH echo "2 "+ env.GIT_BRANCH } Both values are "null" 回答1: I found that I can capture the return value from checkout scm and use that to get the branch name (and other values) def scmVars node('api-sample-build')

How to know which user answered a Jenkins-Pipeline input step?

蓝咒 提交于 2019-12-10 02:45:06
问题 I have a Jenkinsfile script that tests for the possibility to perform an SVN merge and then asks the user for the permission to commit the merge. I would like to know the username that answers the "input" step in order to write it into the commit message. Is this possibile? This is what hypothetically I would like to do: outcome = input message: 'Merge trunk into branch?', ok: 'Merge' echo "User that allowed merge: ${outcome.user}" 回答1: The input step got an optional submitterParameter, which

How to get the current build's node name in jenkins using groovy

我的梦境 提交于 2019-12-10 02:43:40
问题 I have a pipeline job running in Jenkins and I want to know the name of the node it's running on. Is there a way to get the node name from within the job's Groovy script? I have tried the below code: print currentBuild.getBuiltOn().getNodeName() the error is: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method org.jenkinsci.plugins.workflow.job.WorkflowRun getBuiltOn I also tried this: def build = currentBuild.build() print build.getExecutor().getOwner()

How to set Jenkins Declarative Pipeline environments with Global Variables?

风流意气都作罢 提交于 2019-12-10 00:14:24
问题 I am trying to do this pipeline { agent any environment { LOCAL_BUILD_PATH=env.WORKSPACE+'/build/' } stages { stage('Stuff'){ steps{ echo LOCAL_BUILD_PATH } } } } Result: null/build/ How can I use Global Environments to create my environments? 回答1: I think you should use: steps { echo "${env.LOCAL_BUILD_PATH}" } as in "environment" step you're defining environmental variables which are later accessible by env.your-variable-name 回答2: So this is method that I ended up using pipeline { agent {

How to clear workspace in Jenkins pipeline before job starts

☆樱花仙子☆ 提交于 2019-12-09 16:22:12
问题 I need to clear workspace before build starts. I tried using cleanDir() in stages, but in the declarative pipeline, check out happens first and when stage with cleadDir runs, checked out code also gets cleared which is not desired. How can we clear the workspace before check out in the declarative pipeline? 回答1: Use the means of your VCS, with Git run git clean -fdx 回答2: Actually, I have to revise my answer based on recent changes to the pipeline plugins, e.g. GitHub Branch Source Plugin 2.2

Run Powershell script from file in Jenkins pipeline

你说的曾经没有我的故事 提交于 2019-12-09 13:33:04
问题 I am trying to run a Powershell script from a file in a Jenkins pipeline. I have read this which shows how to run powershell scripts that are entered into the pipeline, but I can't get a script to run from a file. I have tried: powershell returnStatus: true, script: '-File build.ps1' and various combinations but can't figure out how to do this. 回答1: Figured it out soon after, the line should have read powershell returnStatus: true, script: '.\\build.ps1' 来源: https://stackoverflow.com

How to add a post build action in the pipeline in Jenkins

若如初见. 提交于 2019-12-09 11:00:57
问题 Below is my pipeline script node(Slave01) { currentBuild.displayName = "${URL_Name}" } stage 'Pt2ctf process' node(Slave01) { build job: 'Pt2ctf_16_7', parameters: [string(name: 'URL_Name', value: "${URL_name}"), string(name: 'Display_Name', value: "${Display_Name}")] } stage 'add_fields' node(Slave01) { build job: 'add_fields_16_7', parameters: [string(name: 'URL_Name', value: "${URL_Name}")] } The above groovy script would trigger multiple builds in sequence. I have another build to be run