jenkins-pipeline

How to trigger a jenkins build on specific node using pipeline plugin?

落爺英雄遲暮 提交于 2019-11-27 04:02:26
问题 I have a Jenkins pipeline job called "TestPipeline". I want to trigger a build on 2 different slaves which labeled "tester1' and "tester2". And the pipeline script is quite simple here: node('tester1') { build 'test_job' } node('tester2') { build 'test_job' } However when I run the TestPipeline job, the "test_job" won't run on the nodes which I assigned. But run on random node instead. I'm wondering if I should set "Restrict where this project can be run" on my "test_job". So I set it to

Error “The input device is not a TTY”

北城以北 提交于 2019-11-27 03:58:32
问题 I am running the following command from my Jenkinsfile . However, I get the error "The input device is not a TTY" . docker run -v $PWD:/foobar -it cloudfoundry/cflinuxfs2 /foobar/script.sh Is there a way to run the script from the Jenkinsfile without doing interactive mode? I basically have a file called script.sh that I would like to run inside the Docker container. 回答1: Remove the -it from your cli to make it non interactive and remove the TTY. If you don't need either, e.g. running your

how to get $CAUSE in workflow

此生再无相见时 提交于 2019-11-27 03:47:29
问题 Jenkins has a $CAUSE variable available to freestyle build jobs. How can I access this or something similar in workflow? My team makes use of it in email output of existing ad-hoc builds. We'd like to continue the same in new workflow based jobs. 回答1: It looks like Workflow builds don't have this variable injected. However you can retrieve the required info from currentBuild.rawBuild object using hudson.model.Run.getCause() or hudson.model.Run.getCauses() method. Example: Workflow script:

Using FilePath to access workspace on slave in Jenkins pipeline

爱⌒轻易说出口 提交于 2019-11-27 02:27:34
问题 I need to check for the existence of a certain .exe file in my workspace as part of my pipeline build job. I tried to use the below Groovy script from my Jenkinsfile to do the same. But I think the File class by default tries to look for the workspace directory on jenkins master and fails. @com.cloudbees.groovy.cps.NonCPS def checkJacoco(isJacocoEnabled) { new File(pwd()).eachFileRecurse(FILES) { it -> if (it.name == 'jacoco.exec' || it.name == 'Jacoco.exec') isJacocoEnabled = true } } How to

Jenkins Workflow Checkout Accessing BRANCH_NAME and GIT_COMMIT

江枫思渺然 提交于 2019-11-27 02:16:58
问题 I cannot seem to extract $GIT_COMMIT and $BRANCH_NAME from a Jenkins Workflow Checkout step. I would like to be able to send this information through to my Gradle scripts in order to pass it onto external sources such as Static analysis etc. Currently I try to run this: checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[credentialsId: '2b74a351-67d5-4d00-abd3-49842a984201', url: 'ssh://git@corporate.com:repo.git']]]) And I would like to achieve the following or

How do I configure a Jenkins Pipeline to be triggered by polling SubVersion?

送分小仙女□ 提交于 2019-11-27 02:12:21
问题 We have been using Jenkins for Continuous Integration for some time. A typical build job specifies the SVN repository and credentials in the "Source Code Management" section, then in the "Build Triggers" section we enable "Poll SCM" with a polling schedule of every 10 minutes (H/10 * * * *). We have updated to the latest version of Jenkins and are looking to set up pipeline builds. A typical pipeline script looks like: node { stage 'Build' build job: 'MyApplication Build' stage 'Deploy to

Jenkins Pipeline Job with file parameter

流过昼夜 提交于 2019-11-27 01:48:01
问题 I'm putting together a Jenkins pipeline job which will take a file parameter. I can trigger the job and point it at a file however I can't find where the file has ended up (In an ordinary freestyle job it would be in the workspace). Where has the uploaded file gone? Or do file parameters not currently work with pipelines? 回答1: There is currently an issue with pipeline and file parameter (https://issues.jenkins-ci.org/browse/JENKINS-27413). 回答2: Solved it the following way: node { deleteDir()

How to access parameters in a Parameterized Build?

风流意气都作罢 提交于 2019-11-27 01:23:20
How do you access parameters set in the "This build is parameterized" section of a "Workflow" Jenkins job? TEST CASE Create a WORKFLOW job. Enable "This build is parameterized". Add a STRING PARAMETER foo with default value bar text . Add the code below to Workflow Script : node() { print "DEBUG: parameter foo = ${env.foo}" } Run job. RESULT DEBUG: parameter foo = null Nick I think the variable is available directly, rather than through env, when using Workflow plugin. Try: node() { print "DEBUG: parameter foo = ${foo}" } I tried a few of the solutions from this thread. It seemed to work, but

Scripted jenkinsfile parallel stage

空扰寡人 提交于 2019-11-27 00:57:08
问题 I am attempting to write a scripted Jenkinsfile using the groovy DSL which will have parallel steps within a set of stages. Here is my jenkinsfile: node { stage('Build') { sh 'echo "Build stage"' } stage('API Integration Tests') { parallel Database1APIIntegrationTest: { try { sh 'echo "Build Database1APIIntegrationTest parallel stage"' } finally { sh 'echo "Finished this stage"' } }, Database2APIIntegrationTest: { try { sh 'echo "Build Database2APIIntegrationTest parallel stage"' } finally {

How to implement Post-Build stage using Jenkins Pipeline plug-in?

泪湿孤枕 提交于 2019-11-27 00:50:48
问题 After reading Jenkins tutorial explaining Pipeline plug-in, it seems that plug-in should make it possible to implement Post-Build steps. However documentation is rather limited in regard to specific instructions. For example I wonder how to implement: Run only if build succeeds Run only if build succeeds or is unstable Run regardless of build result Run only if build succeeds stage 'build' ... build ... tests stage 'post-build' ... (Or add -Dmaven.test.failure.ignore=false to the MAVEN_OPTS )