jenkinsfile

How can I reference the Jenkinsfile directory, with Pipeline?

荒凉一梦 提交于 2019-12-02 21:56:35
I have a groovy file, I want to run from the Jenkinsfile. ie. load script.groovy However, I am not sure how I can reference this file if it is stored in the same directory as the Jenkinsfile. I am loading the Jenkinsfile from git. I noticed it creates a folder called workspace@script . It does not place this in the workspace directory. I could hardcode the folder but I am not sure the rules on this and it seems a little redundant to check-out the code again. java.io.FileNotFoundException: /opt/jenkins_home/jobs/my_job/workspace/script.groovy (No such file or directory) By default it loads from

How do I implement a retry option for failed stages in Jenkins pipelines?

别说谁变了你拦得住时间么 提交于 2019-12-02 16:35:17
I have a Jenkinsfile with multiple stages and one of them is in fact another job (the deploy one) which can fail in some cases. I know that I can made prompts using Jenkinsfile but I don't really know how to implement a retry mechanism for this job. I want to be able to click on the failed stage and choose to retry it. fchaillou You should be able to combine retry + input to do that Something like that stage('deploy-test') { try { build 'yourJob' } catch(error) { echo "First build failed, let's retry if accepted" retry(2) { input "Retry the job ?" build 'yourJob' } } } you could also use

How to perform actions for failed builds in Jenkinsfile

这一生的挚爱 提交于 2019-11-30 11:48:28
Is there a way to perform cleanup (or rollback) if the build in Jenkinsfile failed? I would like to inform our Atlassian Stash instance that the build failed (by doing a curl at the correct URL). Basically it would be a post step when build status is set to fail. Should I use try {} catch () ? If so, what exception type should I catch? I'm currently also searching for a solution to this problem. So far the best I could come up with is to create a wrapper function that runs the pipeline code in a try catch block. If you also want to notify on success you can store the Exception in a variable

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

Configuration of includedRegions in Jenkinsfile?

随声附和 提交于 2019-11-29 17:53:16
问题 How can I limit the scope of a Jenkins pipeline project to only be built if a file in specific subdirectory is changed using Jenkinsfile ? I have a single Git repository with two directories. Each directory contains a separate subproject and I would like to build each subproject separately by Jenkins using Jenkinsfile . The project has the following file structure: parent | +- subA | | | + Jenkinsfile | + more files related to sub project A | +- subB | + Jenkinsfile + more files related to

Set the pipeline name and description from Jenkinsfile

旧巷老猫 提交于 2019-11-29 09:22:23
I am trying to do a poc of jenkins pipeline as code. I am using the Github organization folder plugin to scan Github orgs and create jobs per branch. Is there a way to explicitly define the names for the pipeline jobs that get from Jenkinsfile? I also want to add some descriptions for the jobs. You need to use currentBuild like below. The node part is important node { currentBuild.displayName = "$yournamevariable-$another" currentBuild.description = "$yourdescriptionvariable-$another" } Edit: Above one renames build where as Original question is about renaming jobs. Following script in

Jenkins: Trigger Multi-branch pipeline on upstream change

大憨熊 提交于 2019-11-28 17:35:01
I am currently testing the pipeline approach of Jenkins 2.0 to see if it works for the build environment I am using. First about the environment itself. It currently consists of multiple SCM repositories. Each repository contains multiple branches, for the different stages of the development and each branch is build with multiple configurations. Not all configurations apply to every repository. Currently every repository/branch is setup as a Matrix Project for the different configurations. Each project exposes it's building results as a artifact and these artifacts are used in the downstream

Retrieve all properties of env in Jenkinsfile

不羁的心 提交于 2019-11-28 03:00:36
问题 I would like to print all available properties (and their values) in env object inside Jenkinsfile. When I do print env I get: org.jenkinsci.plugins.workflow.cps.EnvActionImpl@112cebc2 So it looks like toString is not implemented there, how can I access properties that are in this object if I don't know their names? 回答1: Make sure you're not running the pipeline script in sandboxed mode and you should be able to use: env.getEnvironment() Note, if you're running in sandbox mode in a pipeline,

Set the pipeline name and description from Jenkinsfile

浪尽此生 提交于 2019-11-27 23:28:50
问题 I am trying to do a poc of jenkins pipeline as code. I am using the Github organization folder plugin to scan Github orgs and create jobs per branch. Is there a way to explicitly define the names for the pipeline jobs that get from Jenkinsfile? I also want to add some descriptions for the jobs. 回答1: You need to use currentBuild like below. The node part is important node { currentBuild.displayName = "$yournamevariable-$another" currentBuild.description = "$yourdescriptionvariable-$another" }

How to pass variables from Jenkinsfile to shell command

点点圈 提交于 2019-11-27 22:55:55
I want to use a variable which I am using inside of my Jenkinsfile script, and then pass its value into a shell script execution (either as an environment variable or command line parameter). But the following Jenkinsfile : for (i in [ 'a', 'b', 'c' ]) { echo i sh 'echo "from shell i=$i"' } Gives the output: a from shell i= b from shell i= c from shell i= Desired output is something like: a from shell i=a b from shell i=b c from shell i=c Any idea how to pass the value of i to the shell scipt? Edit: Based upon Matt's answer, I now use this solution: for (i in [ 'a', 'b', 'c' ]) { echo i sh "i=