jenkins-workflow

How to set up a github pull request build in a Jenkinsfile?

和自甴很熟 提交于 2019-12-03 11:31:24
问题 So, I've been using Jenkins for quite a while. I have set up numerous projects with the Github Pull Request Builder plugin to run tests whenever someone opens a pull request, and then trigger some other job (build, push, deploy, etc) whenever the pull request actually gets merged to master. So, is there any way to set this up with a Jenkinsfile, or the organization folders, or the multibranch build deal? 回答1: The github-organization-folder plugin in combination with the multi-branch plugin

try/catch/finally masks Jenkinsfile problems in case of groovy compiler exceptions

三世轮回 提交于 2019-12-03 10:54:43
问题 I have code similar to the one below in my Jenkinsfile: node { checkout scm // do some stuff try { // do some maven magic } catch (error) { stage "Cleanup after fail" emailext attachLog: true, body: "Build failed (see ${env.BUILD_URL}): ${error}", subject: "[JENKINS] ${env.JOB_NAME} failed", to: 'someone@example.com' throw error } finally { step $class: 'JUnitResultArchiver', testResults: '**/TEST-*.xml' } } If the above code fails because of some jenkins-pipeline related errors in the try {

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

落花浮王杯 提交于 2019-12-03 09:49:10
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 = sh('git config --get remote.origin.url').exitcode Is this possible? philbert Yes as luka5z mentioned

Jenkins pipeline plugin: set the build description

此生再无相见时 提交于 2019-12-03 08:58:31
问题 I'm trying to replace our current build pipeline, currently hacked together using old-school Jenkins jobs, with a new job that uses the Jenkins pipeline plugin, and loads a Jenkinsfile from the project repository. One thing that the legacy job did was set the build description to include the Mercurial hash, username and current version using the Description setter plugin, so that builds are easy to find. Is there a way to replicate/emulate this behaviour with the Jenkins pipeline plugin? 回答1:

How can I reference the Jenkinsfile directory, with Pipeline?

喜夏-厌秋 提交于 2019-12-03 08:14:28
问题 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:

Kick off a job after manual approval in jenkins

白昼怎懂夜的黑 提交于 2019-12-03 06:02:32
I have a requirement of trigerring a Job B after Job A executes successfully. After Job A executes successfully , an email notification will be sent to the approver . The approver will receive an email and click on the mail link . He will be routed to Jenkins page where he will approve the execution of Job B . I am not sure which plugin to use where I can mention the name of the approver , how the approver can click on the link and simple say "approve" after logging in to the Jenkins page. Setup Job A Configure Job A to send email to your "approver" as part of Email Ext post-build action

How to call REST from jenkins workflow

会有一股神秘感。 提交于 2019-12-03 05:44:11
问题 I wonder how to call REST API from a (groovy) Jenkins workflow script. I can execute "sh 'curl -X POST ...'" - it works, but building the request as a curl command is cumbersome and processing the response gets complicated. I'd prefer a native Groovy HTTP Client to program in groovy - which one should I start with? As the script is run in Jenkins, there is the step of copying all needed dependency jars to the groovy installation on Jenkins, so something light-weight would be appreciated. 回答1:

Create resusable jenkins pipeline script

狂风中的少年 提交于 2019-12-03 03:40:06
问题 I am considering to use Jenkins pipeline script recently, one question is that I don't figure out a smart to way to create internal reusable utils code, imagine, I have a common function helloworld which will be used by lots of pipeline jobs, so I hope to create a utils.jar can injected it into the job classpath. I notice Jenkins have a similar concept with the global library, but my concern regarding this plugin: Since it is a plugin, so we need to install/upgrade it through jenkins plugin

try/catch/finally masks Jenkinsfile problems in case of groovy compiler exceptions

我只是一个虾纸丫 提交于 2019-12-03 02:26:13
I have code similar to the one below in my Jenkinsfile: node { checkout scm // do some stuff try { // do some maven magic } catch (error) { stage "Cleanup after fail" emailext attachLog: true, body: "Build failed (see ${env.BUILD_URL}): ${error}", subject: "[JENKINS] ${env.JOB_NAME} failed", to: 'someone@example.com' throw error } finally { step $class: 'JUnitResultArchiver', testResults: '**/TEST-*.xml' } } If the above code fails because of some jenkins-pipeline related errors in the try { } (e.g. using unapproved static method) the script fails silently. When I remove the try/catch/finally

How to set up a github pull request build in a Jenkinsfile?

為{幸葍}努か 提交于 2019-12-03 01:54:15
So, I've been using Jenkins for quite a while. I have set up numerous projects with the Github Pull Request Builder plugin to run tests whenever someone opens a pull request, and then trigger some other job (build, push, deploy, etc) whenever the pull request actually gets merged to master. So, is there any way to set this up with a Jenkinsfile, or the organization folders, or the multibranch build deal? The github-organization-folder plugin in combination with the multi-branch plugin plugin offers exactly this awesome feature: It scans a whole organization (optionally restricted to certain