jenkins-pipeline

Jenkins pipeline how to change to another folder

喜夏-厌秋 提交于 2019-11-30 13:35:34
问题 Currently i am using Jenkins pipeline script. For running one command, I need to access a folder outside its workspace directory. I tried sh "cd $workspace/" , but it returned current workspace folder. How I can change to root workspace directory and then cd to another folder. Please help. 回答1: You can use the dir step, example: dir("folder") { sh "pwd" } The folder can be relative or absolute path. 回答2: Use WORKSPACE environment variable to change workspace directory. If doing using

How to mount Jenkins workspace in docker container using Jenkins pipeline

二次信任 提交于 2019-11-30 12:54:38
问题 I'm using Jenkins in docker. The /var/jenkins_home is mounted on /var/jenkins-data on my host. My Jenkins can execute docker commands (mount of sockets) and I've installed the git plugin and pipeline plugin. Now I have a pipeline job named test and the following pipeline: pipeline { agent any stages { stage('Clone') { steps { git branch: 'master', url: 'https://github.com/lvthillo/maven-hello-world.git' } } stage('Build in Docker') { agent { docker { image 'maven:3.5.2' args '-v /var/jenkins

Try-catch block in Jenkins pipeline script

痴心易碎 提交于 2019-11-30 12:47:39
问题 I'm trying to use the following code to execute builds, and in the end, execute post build actions when builds were successful. Still, I get a MultipleCompilationErrorsException, saying that my try block is Not a valid section definition. Please help, I tried a lot reorganize the block but can't seem to be able to solve the issue. #!/usr/bin/env groovy pipeline{ agent any try { stages{ stage("Parallel 1") { steps { parallel ( 'firstTask' : { build( "DSL-Controll-Demo-Fibonacci-1" ) },

What does a ws() block do in Jenkins?

◇◆丶佛笑我妖孽 提交于 2019-11-30 12:04:35
I'm trying to convert few Jenkinsfile s from Scripted Pipeline to Declarative Pipeline . I have a block like this in a Jenkinsfile : ws("/path/to/dir") { // do stuff } I wonder what does it do exactly and what's the proper way to convert it to the Declarative Pipeline syntax. ws allocates a new workspace. you would use this to ensure that nothing else interferes with the location on disk where you are running the enclosed steps. this is not as heavy-handed as the node step, since node will also ensure that it gets run with a separate executor. this provides more isolation than the dir step,

Jenkins pipeline bubble up the shell exit code to fail the stage

我与影子孤独终老i 提交于 2019-11-30 12:00:12
问题 Absolute Jenkins pipeline/groovy noob here, I have a stage stage('Building and Deploying'){ def build = new Build() build.deploy() } which is using the shared lib, the source of the Build.groovy is here: def deploy(branch='master', repo='xxx'){ if (env.BRANCH_NAME.trim() == branch) { def script = libraryResource 'build/package_indexes/python/build_push.sh' // TODO: Test out http://stackoverflow.com/questions/40965725/jenkins-pipeline-cps-global-lib-resource-file-for-shell-script-purpose

Get username logged in Jenkins from Jenkins Workflow (Pipeline) Plugin

倖福魔咒の 提交于 2019-11-30 11:55:49
问题 I am using the Pipeline plugin in Jenkins by Clouldbees (the name was Workflow plugin before), I am trying to get the user name in the Groovy script but I am not able to achieve it. stage 'checkout svn' node('master') { // Get the user name logged in Jenkins } 回答1: Did you try installing the Build User Vars plugin? If so, you should be able to run node { wrap([$class: 'BuildUser']) { def user = env.BUILD_USER_ID } } or similar. 回答2: To make it work with Jenkins Pipeline: Install user build

Jenkins Pipeline accessing environment variables

夙愿已清 提交于 2019-11-30 11:51:22
问题 I'm trying to use DSL pipelines in Jenkins. I thought it'd be nice if I could use the project name as part of my script. git credentialsId: 'ffffffff-ffff-ffff-ffff-ffffffffffffff',\ url: "${repo_root}/${JOB_NAME}.git" I get the error: groovy.lang.MissingPropertyException: \ No such property: JOB_NAME for class: groovy.lang.Binding I thought I followed these directions, and they mention JOB_NAME as one of the variables. I decided to try: sh 'env' in my DSL, and this prints out: JOB_NAME = foo

How to make Pipeline job to wait for all triggered parallel jobs?

六月ゝ 毕业季﹏ 提交于 2019-11-30 11:30:22
I've Groovy script as part of the Pipeline job in Jenkins as below: node { stage('Testing') { build job: 'Test', parameters: [string(name: 'Name', value: 'Foo1')], quietPeriod: 2, wait: false build job: 'Test', parameters: [string(name: 'Name', value: 'Bar1')], quietPeriod: 2, wait: false build job: 'Test', parameters: [string(name: 'Name', value: 'Baz1')], quietPeriod: 2, wait: false build job: 'Test', parameters: [string(name: 'Name', value: 'Foo2')], quietPeriod: 2, wait: false build job: 'Test', parameters: [string(name: 'Name', value: 'Bar2')], quietPeriod: 2, wait: false build job: 'Test

Jenkins multibranch pipeline with Jenkinsfile from different repository

北战南征 提交于 2019-11-30 11:17:18
I have a Git repository with code I'd like to build but I'm not "allowed" to add a Jenkinsfile in its root (it is a Debian package so I can't add files to upstream source). Is there a way to store the Jenkinsfile in one repository and have it build code from another repository? Since my code repository has several branches to build (one for each Debian release) this should be a multibranch pipeline. Commits in either the code or Jenkinsfile repositories should trigger a build. Bonus complexity: I have several code/packaging repositories like this and I'd like to reuse the same Jenkinsfile for

How to get the BUILD_USER in Jenkins when job triggered by timer?

强颜欢笑 提交于 2019-11-30 11:08:42
I wanted to show the user who triggered a Jenkins job in the post job email. This is possible by using the plugin Build User Vars Plugin and the env variable BUILD_USER . But this variable do not get initialized when the job is triggered by a scheduler. How can we achieve this? I know we have a plugin called - EnvInject Plugin, and that can be used... But I just want to know how we can use this and achieve the solution... Musaffir Lp This can be done using the Jenkins Build User Vars Plugin which exposes a set of environment variables, including the user who started the build. It gives