jenkins-pipeline

How to get the pipeline configuration field 'Script Path' when executing the Jenkinsfile?

旧巷老猫 提交于 2019-12-13 16:31:20
问题 How can I get the content of the pipeline configuration field 'Script Path' in Jenkins from the Jenkinsfile (groovy)? In this example: I want to get the string 'Apps/mq-logger/Jenkinsfile' when executing the Jenkinsfile itself. 回答1: You can get a script path this way def scriptPath = currentBuild.rawBuild.parent.definition.scriptPath Note that you have to approve all these methods. 回答2: If you want this string to be customizable during the build time, you can create a parameterized build as

How to use groovy env. variable in Jenkins to pass through bat command in Jenkins pipeline

荒凉一梦 提交于 2019-12-13 16:20:30
问题 I have stage in my jenkinsfile, that executes a bat command: stage ('build'){ bat '%cd%\\MySimpleProject\\bin\\Execute.bat "${env.BRANCH_NAME}"' } My batch command requires a parameter that is the current branch in svn. When I use this: echo "SVN_BRANCH_NAME is ${env.BRANCH_NAME}" It would give the value of BRANCH_NAME but if I pass it as param to my batch file, it literally pass ${env.BRANCH_NAME} not the value. Is their a way to do this? 回答1: It's because all is wrapped in single quotes and

How to load files from resources folder in Shared library without knowing their names (or number)?

左心房为你撑大大i 提交于 2019-12-13 16:17:06
问题 As you know, in Shared libraries in Jenkins, it is possible to load a resource (located in resources folder) by doing: libraryResource("script.sh") Now my use case is that I want to load number of files inside a folder under resources : + resources + teamA + script1.sh + script2.sh And I want to load all those files before doing anything : I did a method in the shared library: new File(scriptsFolder).eachFile() { file-> writeFile([file:"${env.workspace}/${file.getName()}",text:libraryResource

How to use the Groovy Expression from the Lockable Resources Plugin in Jenkins Freestyle projects

a 夏天 提交于 2019-12-13 15:22:16
问题 This question was asked in relation to an old version of Lockable Resources Plugin. The error in the old versions have been fixed since version 2.1. The answers for how to properly use the Groovy Expression in the freestyle jobs are however not described. I will add an answer to explain this. The original question follows, for those with an interest: I'm was initially attempting to get the Lockable Resources Plugin to lock on a specific resource while also evaluation the value of a system

Suppress Scripted Pipelines Output in Jenkins

橙三吉。 提交于 2019-12-13 13:45:32
问题 I'm relatively new to Jenkins and was wondering if there are any examples on suppressing scripted pipelines output in Jenkins . I see this issue on jenkins website, but I'm not exactly sure how to implement. I also didn't see a clear answer from a question on Stack Overflow about this issue. I basically want to get rid of all the Pipeline stuff: $ docker top 5f4682c000c81cbede8dc72f190b25254e049e9607ba008cbad72a78adab56a2 -eo pid,comm [Pipeline] { [Pipeline] stage [Pipeline] { (Check Style)

What's the pattern evaluation on Jenkinsfile when-branch setting?

佐手、 提交于 2019-12-13 12:04:14
问题 I am trying to detect the branch pattern on a when statement inside a stage. Like this: stage('deploy to staging') { agent label:'some-node' when { branch "feature/*" } steps { sh './deploy_pr.sh' } } What if I want a more complicated pattern? I am trying to detect something like feature/0.10.25 and the following pattern doesn't work: when { branch 'feature/[0-9]+.[0-9]+.[0-9]+' } Doesn't work . And it's a correct regexp, according to https://regexr.com/ 回答1: Ok ! So, through the error stack

installing node on jenkins 2.0 using the pipeline plugin

落花浮王杯 提交于 2019-12-13 11:58:07
问题 I am running the following docker image jenkinsci/jenkins:2.0-rc-1 to try out jenkins 2.0, and the "pipeline" view. I can't seem to install node. Here's my pipeline script: node { //tool([name: 'node-5.10.1', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation']) sh 'echo $(whoami)' sh 'node -v' } The response when this runs is: [ci] Running shell script + whoami + echo jenkins jenkins [Pipeline] sh [ci] Running shell script + node -v /../durable-3b0b1b07/script.sh: 2: /../durable-3b0b1b07

How to check if build parameter is available in Jenkinsfile

拥有回忆 提交于 2019-12-13 11:40:58
问题 I have a pipeline script that should work with and without parameters. So I have to check if the parameter is available. I tried if(getBinding().hasVariable("myparameter")) but this leads to an Exception org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.Binding getVariables Is there another way to check if the job is parameterized? 回答1: Newer versions make the parameters available through the params variable. If the parameter

How to execute a command in a Jenkins 2.0 Pipeline job and then return the stdout

假如想象 提交于 2019-12-13 11:38:37
问题 Is there a better way to run a shell task in a Jenkins 2.0 pipeline and then return the stdout of the command. The only way I can get this to work is to pipe the output of the command to a file and then read the file in to a variable. sh('git config --get remote.origin.url > GIT_URL') def stdout = readFile('GIT_URL').trim() This seems like a really bad way to return the output. I was hoping I could do something like: def stdout = sh('git config --get remote.origin.url').stdout or def exitcode

I want to merge one project data into another project in jenkins. How can I achieve this?

随声附和 提交于 2019-12-13 08:28:50
问题 I have two project namely say X and Y Where x contains all code and configuration And Y contains testData and Feature files which is manage by some other team. I had created a job in jenkins to run my X project initially which is working without any issue. Now I want at run time I poll the Y project and check if they had any new commits then first I merge it else leave it. Currently I am able to check the last commit but still not able to merge project My both X and Y are Karate API project