jenkins-pipeline

Jenkins build fail for PR from GitHub

三世轮回 提交于 2019-12-17 20:24:22
问题 I'm using jenkins pipeline to build my github project. When I raise a pull request (PR) on GitHub, its creating a job "pr-head" which fails all the time with below error Let me know if you have any suggestions for this Even the answers in Git PullRequest job failed. Couldn't find any revision to build. Verify the repository and branch configuration for this job did not solve my problem 回答1: Update 2019/03/22: Quick anser Use a refspec which fits your git server's PR handling. E.g. for

Groovy .each only iterates one time

梦想的初衷 提交于 2019-12-17 18:52:51
问题 The script is not iterating through all the values of the 'modules' array. class Module { public String name = ''; public Boolean isCustom = false; public Module(String name, Boolean custom){ this.name = name; this.isCustom = custom; } } //creates array from the ext_module env var modules = []; EXT_MODULE.split(',').each { modules.add(new Module(it, false)); } println modules; modules.each { println "MODULE NAME ::::: ${it.name}" if(it.isCustom) { println "install custom"; } else { println

How to get the git latest commit message and prevent the jenkins build if the commit message contains [ci skip]?

若如初见. 提交于 2019-12-17 18:34:54
问题 I tried to get the git commit message in jenkinsfile and prevent the build based on commit message. env.GIT_COMMIT doesn't return the commit details in jenkinsfile. How to get the git latest commit message and prevent the jenkins build if the commit message contains [ci skip] in it? 回答1: The build will pass when [ci skip] is provided in the last git log, but will not run the actual build code (the replacement to the first echo statement) node { checkout scm result = sh (script: "git log -1 |

Git Variables in Jenkins Workflow plugin

大憨熊 提交于 2019-12-17 17:43:29
问题 I'd like to access git variables such as GIT_COMMIT and GIT_BRANCH when I have checked out a repository from git further down in the build stream. Currently I find no available variable to access these two parameters. node { git git+ssh://git.com/myproject.git echo "$GIT_COMMIT - $BRANCH_NAME" } Is such variables available and in case, where would I find them. I don't mind if they are available through some groovy variables or wherever, just that I can access them. Maybe I lack the debugging

How to invoke a jenkins pipeline A in another jenkins pipeline B

a 夏天 提交于 2019-12-17 17:36:41
问题 I have two Jenkins pipelines, let's say pipeline-A and pipeline-B. I want to invoke pipeline-A in pipeline-B. How can I do this? (pipeline-A is a subset of pipeline-B. Pipeline-A is responsible for doing some routine stuff which can be reused in pipeline-B) I have installed Jenkins 2.41 on my machine. 回答1: A little unclear if you want to invoke another pipeline script or job, so I answer both: Pipeline script The "load" step will execute the other pipeline script. If you have both scripts in

Checkout Jenkins Pipeline Git SCM with credentials?

强颜欢笑 提交于 2019-12-17 17:33:20
问题 I was following this tutorial: node { git url: 'https://github.com/joe_user/simple-maven-project-with-tests.git' ... } However it doesn't tell how to add credentials. Jenkins does have specific "Credentials" section where you define user user&pass, and then get ID for that to use in jobs, but how do I use that in Pipeline instructions? I tried with: git([url: 'git@bitbucket.org:company/repo.git', branch: 'master', credentialsId: '12345-1234-4696-af25-123455']) no luck: stderr: Host key

How to pass variables from Jenkinsfile to shell command

假装没事ソ 提交于 2019-12-17 16:16:21
问题 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

Abort current build from pipeline in Jenkins

时间秒杀一切 提交于 2019-12-17 10:33:29
问题 I have a Jenkins pipeline which has multiple stages, for example: node("nodename") { stage("Checkout") { git .... } stage("Check Preconditions") { ... if(!continueBuild) { // What do I put here? currentBuild.xxx ? } } stage("Do a lot of work") { .... } } I want to be able to cancel (not fail) the build if certain preconditions are not met and there is no actual work to be done. How can I do this? I know the currentBuild variable is available, but I can't find the documentation for it. 回答1:

Jenkins Build Pipeline - Restart At Stage

☆樱花仙子☆ 提交于 2019-12-17 10:26:48
问题 I have the following build pipeline set up as a job: Stage 1 - verify all dependencies exist Stage 2 - build the new jar Stage 3 - Run integration tests Stage 4 - Deploy to staging environment (manual step) Stage 5 - Deploy to production environment (manual step) I am looking for a way to start the build pipeline from a particular stage in case of a transient failure. For example, let's say there was a network issue when the user clicked to deploy to production. I don't think it makes sense

“Build Periodically” with a Multi-branch Pipeline in Jenkins

做~自己de王妃 提交于 2019-12-17 08:37:08
问题 I'm running Jenkins 2 with the Pipeline plugin. I have setup a Multi-branch Pipeline project where each branch (master, develop, etc.) has a Jenkinsfile in the root. Setting this up was simple. However, I'm at a loss for how to have each branch run periodically (not the branch indexing), even when the code does not change. What do I need to put in my Jenkinsfile to enable periodic builds? 回答1: If you use a declarative style Pipeline and only want to trigger the build on a specific branch you