jenkins-pipeline

How to catch manual UI cancel of job in Jenkinsfile

妖精的绣舞 提交于 2019-12-03 12:45:45
I've tried to find documentation about how in a Jenkinsfile pipeline catching the error that occurs when a user cancels a job in jenkins web UI. I haven't got the post or try/catch/finally approaches to work, they only work when something fails within the build. This causes resources not to be free'd up when someone cancels a job. What I have today, is a script within a declarative pipeline , like so: pipeline { stage("test") { steps { parallell ( unit: { node("main-builder") { script { try { sh "<build stuff>" } catch (ex) { report } finally { cleanup } } } } ) } } } So, everything within

Unknown stage section “withSonarQubeEnv”

ぃ、小莉子 提交于 2019-12-03 12:36:42
问题 I am experimenting using Pipeline jobs with the Blue Ocean beta plugin enabled on our Jenkins server. We have a sonarqube scanner build step configured in one of our freestyle jobs, which I now want to add a stage for in my Jenkins file. I see from the sonar docs there is a way to achieve this here We are using Jenkins 2.32.3 and have SonarQube scanner 2.8 installed. I tried the suggested stage config block, where our scanner is named 'SonarQube Scanner' stage('SonarQube analysis') { //

Why an each loop in a Jenkinsfile stops at first iteration

一世执手 提交于 2019-12-03 11:45:19
问题 Here is the content of my Jenkinsfile : node { // prints only the first element 'a' [ 'a', 'b', 'c' ].each { echo it } } When executing the job in Jenkins (with the Pipeline plugin), only the first item in the list is printed. Can someone explain me this strange behavior? Is it a bug? or is it just me not understanding the Groovy syntax? Edit : the for (i in items) works as expected : node { // prints 'a', 'b' and 'c' for (i in [ 'a', 'b', 'c' ]) { echo i } } 回答1: The accepted answer here

Is there a way to run a pre-checkout step in declarative Jenkins pipelines?

一笑奈何 提交于 2019-12-03 11:42:54
问题 Jenkins declarative pipelines offer a post directive to execute code after the stages have finished. Is there a similar thing to run code before the stages are running, and most importantly, before the SCM checkout? For example something along the lines of: pre { always { rm -rf ./* } } This would then clean the workspace of my build before the source code is checked out. 回答1: pre is a cool feature idea, but doesn't exist yet. skipDefaultCheckout and checkout scm (which is the same as the

Jenkins pipeline code auto trigger with multiple repositories through GitHub Organization Folder Plugin

不想你离开。 提交于 2019-12-03 11:42:05
This question is related to the Jenkins job auto trigger with multiple repositories. Defined 3 repo's to checkout in Jenkinsfile. node('slave'){ git clone github.com/owner/abc.git -b ${env.BRANCH_NAME} git clone github.com/owner/def.git -b ${env.BRANCH_NAME} git clone github.com/owner/ghi.git -b ${env.BRANCH_NAME} } Configured Jenkins job using Github organization plugin. In this case my Jenkinsfile is in abc repo and the Jenkins auto trigger is working fine for the abc repo. its not working for other repo's. Is there anyway to define auto trigger for 2 or more repo's? Is there any plugin

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

Docker not found when building docker image using Docker Jenkins container pipeline

三世轮回 提交于 2019-12-03 11:25:26
问题 I have a Jenkins running as a docker container, now I want to build a Docker image using pipeline, but Jenkins container always tells Docker not found. [simple-tdd-pipeline] Running shell script + docker build -t simple-tdd . /var/jenkins_home/workspace/simple-tdd-pipeline@tmp/durable- ebc35179/script.sh: 2: /var/jenkins_home/workspace/simple-tdd- pipeline@tmp/durable-ebc35179/script.sh: docker: not found Here is how I run my Jenkins image: docker run --name myjenkins -p 8080:8080 -p 50000

How to disable automatic build from scm change in Jenkinsfile

白昼怎懂夜的黑 提交于 2019-12-03 11:19:23
问题 I have a Jenkinsfile that I've set up with a cron for a pipelineTriggers parameter. I can't seem to figure out how to disable the job from building from a merge to the master branch of the repo. Is there a way in the Jenkinsfile to disable the automatic build from an scm change? 回答1: If you're using a Multibranch Pipeline, you should be able to do this on the job's Configure page: Scroll down to "Branch Sources" Under "Property strategy", choose "Named branches get different properties" Click

Jenkins pipeline: checkout explicit git commit

拜拜、爱过 提交于 2019-12-03 11:08:45
问题 I want to be able to say something like: git branch: commitHash, credentialsId: credentialsId, url: url The usecase: I'm doing parallel build and test runs on different platforms, and want to ensure each gets the same code. It is C++, and we build on separate platforms as well as building on them. If I do the above, it fails - the underlying code assumes the given branch actually is a branch, or you get something like: [Linux64 Build] > git rev-parse origin

Jenkins Docker Pipeline Exit Code -1

懵懂的女人 提交于 2019-12-03 10:57:15
We have a Jenkinsfile that uses the docker plugin to run a script inside a given container. This works fine for some images, but fails immediately with a -1 exit code on others. We've reduced the error down to a simple sleep . This is the Jenkinsfile: node("docker") { def wheezy_image = docker.image("pyca/cryptography-runner-wheezy") wheezy_image.pull() wheezy_image.inside { sh """sleep 120""" } } And here's the jenkins output + docker pull pyca/cryptography-runner-wheezy Using default tag: latest latest: Pulling from pyca/cryptography-runner-wheezy Digest: sha256