jenkins-pipeline

How to set PATH in Jenkins Declarative Pipeline

*爱你&永不变心* 提交于 2019-11-30 10:57:22
In Jenkins scripted pipeline you can set PATH env variable like this : node { git url: 'https://github.com/jglick/simple-maven-project-with-tests.git' withEnv(["PATH+MAVEN=${tool 'M3'}/bin"]) { sh 'mvn -B verify' } } Notice the PATH+MAVEN as explained here https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-withenv-code-set-environment-variables : A list of environment variables to set, each in the form VARIABLE=value or VARIABLE= to unset variables otherwise defined. You may also use the syntax PATH+WHATEVER=/something to prepend /something to $PATH. But I didn't find how to do

Jenkins pipeline how to change to another folder

给你一囗甜甜゛ 提交于 2019-11-30 10:50:48
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. You can use the dir step, example: dir("folder") { sh "pwd" } The folder can be relative or absolute path. Raj Bangarwa Use WORKSPACE environment variable to change workspace directory. If doing using Jenkinsfile, use following code : dir("${env.WORKSPACE}/aQA"){ sh "pwd" } 来源: https://stackoverflow.com

Jenkins how to create pipeline manual step

倾然丶 夕夏残阳落幕 提交于 2019-11-30 10:26:59
问题 Prior Jenkins2 I was using Build Pipeline Plugin to build and manually deploy application to server. Old configuration: That works great, but I want to use new Jenkins pipeline, generated from groovy script (Jenkinsfile), to create manual step. So far I came up with input jenkins step. Used jenkinsfile script: node { stage 'Checkout' // Get some code from repository stage 'Build' // Run the build } stage 'deployment' input 'Do you approve deployment?' node { //deploy things } But this waits

Strange variable scoping behavior in Jenkinsfile

房东的猫 提交于 2019-11-30 08:59:49
When I run the below Jenkins pipeline script: def some_var = "some value" def pr() { def another_var = "another " + some_var echo "${another_var}" } pipeline { agent any stages { stage ("Run") { steps { pr() } } } } I get this error: groovy.lang.MissingPropertyException: No such property: some_var for class: groovy.lang.Binding If the def is removed from some_var , it works fine. Could someone explain the scoping rules that cause this behavior? TL;DR variables defined with def in the main script body cannot be accessed from other methods. variables defined without def can be accessed directly

Is there a way to automatically build tags using the Multibranch Pipeline Jenkins plugin?

笑着哭i 提交于 2019-11-30 08:55:31
After creating a Multibranch Pipeline in Jenkins I can easily tell it to poll for changes or additions of any branches and it will automatically create jobs for and build those branches. I told the Multibranch job to also discover tags, so it automatically creates jobs for each tag, which is great. Is there a clean way for Jenkins to automatically build those tags as well, instead of me having to trigger them manually? As you can see below, the job for the tag is there, but I have to manually build it. I would have commented with this, but I don't have enough reputation. I believe this is a

Jenkins Pipeline Fails if Step is Unstable

本秂侑毒 提交于 2019-11-30 08:26:22
Currently my pipeline fails (red), when a maven-job is unstable (yellow). node { stage 'Unit/SQL-Tests' parallel ( phase1: { build 'Unit-Tests' }, // maven phase2: { build 'SQL-Tests' } // shell ) stage 'Integration-Tests' build 'Integration-Tests' // maven } In this example the job Unit-Test's result is unstable, but is shown as failed in the pipeline. How can I change the jobs/pipeline/jenkins to have the (1) the pipeline step unstable instead of failed and (2) the pipeline's status unstable instead of failed. I tried adding the MAVEN_OPTS parameter -Dmaven.test.failure.ignore=true , but

Jenkins Pipeline sh bad substitution

≡放荡痞女 提交于 2019-11-30 07:58:21
A step in my pipeline uploads a .tar to an artifactory server. I am getting a Bad substitution error when passing in env.BUILD_NUMBER, but the same commands works when the number is hard coded. The script is written in groovy through jenkins and is running in the jenkins workspace. sh 'curl -v --user user:password --data-binary ${buildDir}package${env.BUILD_NUMBER}.tar -X PUT "http://artifactory.mydomain.com/artifactory/release-packages/package${env.BUILD_NUMBER}.tar"' returns the errors: [Pipeline] sh [Package_Deploy_Pipeline] Running shell script /var/lib/jenkins/workspace/Package_Deploy

Share gitlab-ci.yml between projects

孤者浪人 提交于 2019-11-30 07:35:33
We are thinking to move our ci from jenkins to gitlab. We have several projects that have the same build workflow. Right now we use a shared library where the pipelines are defined and the jenkinsfile inside the project only calls a method defined in the shared library defining the actual pipeline. So changes only have to be made at a single point affecting several projects. I am wondering if the same is possible with gitlab ci? As far as i have found out it is not possible to define the gitlab-ci.yml outside the repository. Is there another way to define a pipeline and share this config with

How do I tag the current git changeset from inside the Jenkinsfile?

匆匆过客 提交于 2019-11-30 07:09:28
I want to tag the current git changeset and push the tag from inside the Jenkinsfile. If the tag already exists it must be replaced. I want to use this logic in order to tag the build that passed with the snapshot tag, which would be a mobile tag. How can I do this? sorin Here is the way I was able to implement this this way, but if you know a better way I am more than willing to hear it. #!groovy stage 'build' node { repositoryCommiterEmail = 'ci@example.com' repositoryCommiterUsername = 'examle.com' checkout scm sh "echo done" if (env.BRANCH_NAME == 'master') { stage 'tagging' sh("git config

Jenkins Pipeline sh bad substitution

不想你离开。 提交于 2019-11-30 07:05:32
问题 A step in my pipeline uploads a .tar to an artifactory server. I am getting a Bad substitution error when passing in env.BUILD_NUMBER, but the same commands works when the number is hard coded. The script is written in groovy through jenkins and is running in the jenkins workspace. sh 'curl -v --user user:password --data-binary ${buildDir}package${env.BUILD_NUMBER}.tar -X PUT "http://artifactory.mydomain.com/artifactory/release-packages/package${env.BUILD_NUMBER}.tar"' returns the errors: