jenkins-pipeline

Jenkins Declarative Pipeline: How to read choice from input step?

£可爱£侵袭症+ 提交于 2019-12-03 02:46:37
问题 I'm trying to access a variable from an input step using the declarative pipelines syntax but it seems not to be available via env or params . This is my stage definition: stage('User Input') { steps { input message: 'User input required', ok: 'Release!', parameters: [choice(name: 'RELEASE_SCOPE', choices: 'patch\nminor\nmajor', description: 'What is the release scope?')] echo "env: ${env.RELEASE_SCOPE}" echo "params: ${params.RELEASE_SCOPE}" } } Both echo steps print null . I also tried to

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

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

喜你入骨 提交于 2019-12-03 01:44:39
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:50000 -v /var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins And the DockerFile of

How to disable automatic build from scm change in Jenkinsfile

岁酱吖の 提交于 2019-12-03 01:43:44
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? 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 "Add exception", enter "master" as the branch name Click "Add property", choose "Suppress automatic SCM

Jenkins pipeline: checkout explicit git commit

只愿长相守 提交于 2019-12-03 01:37:53
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/e4b6c976a0a986c348a211579f1e8fd32cf29567^{commit} # timeout=10 [Pipeline] [Linux64 Build] } [Pipeline] [Linux64 Build] // dir [Pipeline]

Grouping and decorating groups of parameters in Jenkins

六月ゝ 毕业季﹏ 提交于 2019-12-03 01:32:53
I'm writing a Jenkins pipeline job with quite a few parameters and I'm looking for a way to visually group them together so they will be easier to understand -rather than have them all just thrown in there. I'll settle for anything that at least hints a the fact that these parameters are related to each other. Could be a header, could be boxes. Is there any plugin that will help me decorate my inputs this way? So, after much searching the web I finally found a plugin that does the trick. The Parameter Separator Plugin . The wiki page doesn't say how to make it work in a pipeline, but after

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

风格不统一 提交于 2019-12-03 01:04:35
问题 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. 回答1: 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

How do I make Jenkins 2.0 execute a sh command in the same directory as the checkout?

ぃ、小莉子 提交于 2019-12-03 00:59:59
Here's my Jenkins 2.x pipeline: node ('master'){ stage 'Checkout' checkout scm stage "Build Pex" sh('build.sh') } When I run this pipeline the checkout puts the code into to the workspace as expected, however instead of expecting to find the script in workspace/ (it's really there!), it looks in an unrelated directory: workspace@tmp/durable-d812f509. Entering stage Build Pex Proceeding [Pipeline] sh [workspace] Running shell script + build.sh /home/conmonsysdev/deployments/jenkins_ci_2016_interns/jenkins_home/jobs/pex/branches/master/workspace@tmp/durable-d812f509/script.sh: line 2: build.sh:

Limiting Jenkins pipeline to running only on specific nodes

你离开我真会死。 提交于 2019-12-03 00:58:56
I'm building jobs that will be using Jenkins piplines extensively. Our nodes are designated per project by their tags, but unlike regular jobs the pipeline build does not seem to have the "Restrict where this project can be run" checkbox. How can I specify on which node the pipeline will run the way I do for regular jobs? You specify the desired node or tag when you do the node step: node('specialSlave') { // Will run on the slave with name or tag specialSlave } See https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-node-code-allocate-node for an extended explanation of the