jenkins-pipeline

Create resusable jenkins pipeline script

我是研究僧i 提交于 2019-12-02 17:08:04
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 manager, then it may require reboot to apply the change, this is not what I want to see since utils may

Jenkins Copy Artifact parse copied build id

依然范特西╮ 提交于 2019-12-02 17:07:23
问题 I'm using in Jenkins 2.73.1, in a multibranch pipeline Copy Artifact Plugin to get the last successful artifacts from two other pipelines, see my Jenkinsfile: def branchname = "${BRANCH_NAME}".replace("/", "%2F") pipeline { agent { label 'windows' } stages { stage('get artifacts') { steps { script { parallel('get-backend': { step([$class: 'CopyArtifact', projectName: "backend/${branchname}", target: 'input/backend']) }, 'get-frontend': { step([$class: 'CopyArtifact', projectName: "frontend/$

Calling shell commands in groovy script, used in Jenkins pipeline

蹲街弑〆低调 提交于 2019-12-02 17:07:22
问题 I have a Jenkins pipeline script in that I load an external Groovy script that contains some functions to perform my build. These functions should be plain groovy because I also want to use them outside of Jenkins, if someone runs a build on a local computer somewhere. In these functions I need to execute shell commands and evaluate the result. This works fine in groovy calling a function like def SomeFunction() { def result = "Some shell command".execute().text } However, this method of

Jenkinsfile and different strategies for branches

时间秒杀一切 提交于 2019-12-02 17:05:08
I'm trying to use Jenkins file for all our builds in Jenkins, and I have following problem. We basically have 3 kind of builds: pull-request build - it will be merged to master after code review, and if build works manual pull-request build - a build that does the same as above, but can be triggered manually by the user (e.g. in case we have some unstable test) an initial continuous deliver pipeline - this will build the code, deploy to repository, install artifacts from repository on the target server and start the application there How should I contain all of the above builds into a single

Conditional step/stage in Jenkins pipeline

假装没事ソ 提交于 2019-12-02 16:55:44
How do you run a build step/stage only if building a specific branch? For example, run a deployment step only if the branch is called deployment , leaving everything else the same. Doing the same in declarative pipeline syntax, below are few examples: stage('master-branch-stuff'){ agent any when{ branch 'master' } steps { echo 'run this stage - ony if the branch = master branch' } } stage('feature-branch-stuff') { agent label:'test-node' when { branch "feature/*" } steps { echo 'run this stage - only if the branch name started with feature/' } } stage('expression-branch') { agent label:'some

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

别说谁变了你拦得住时间么 提交于 2019-12-02 16:35:17
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. fchaillou 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 retry if accepted" retry(2) { input "Retry the job ?" build 'yourJob' } } } you could also use

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

烈酒焚心 提交于 2019-12-02 16:21:22
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 access the variable directly but I got the following error: groovy.lang.MissingPropertyException: No

npm install fails in jenkins pipeline in docker

╄→гoц情女王★ 提交于 2019-12-02 15:48:05
I'm following a tutorial about Jenkins pipeline and I can get a "hello world" working under at node 6.10 docker container. But, when I added a default EmberJS app (using ember init ) to the repo and attempt to build that in the pipeline, it fails when running npm install (because of directory access issues). The Jenkinsfile can be seen here: https://github.com/CloudTrap/pipeline-tutorial/blob/fix-build/Jenkinsfile The error message printed by the build is (which is installed locally and run using java -jar jenkins.war on a Macbook, not relevant but included just in case) is: npm ERR! Linux 4.9

Jenkins scripted pipeline or declarative pipeline

China☆狼群 提交于 2019-12-02 14:25:32
I'm trying to convert my old style project base workflow to a pipeline based on Jenkins. While going through docs I found there are two different syntaxes named scripted and declarative . Such as the Jenkins web declarative syntax release recently (end of 2016). Although there is a new syntax release Jenkins still supports scripted syntax as well. Now, I'm not sure in which situation each of these two types would be a best match. scripted syntax will be deprecated soon? So will declarative be the future of the Jenkins pipeline? Anyone who can share some thoughts about these two syntax types.

Can you parse TAP format using Jenkins Pipeline?

↘锁芯ラ 提交于 2019-12-02 13:38:14
问题 I'm trying to parse the output from a BATS script (https://github.com/gaia-adm/docker-bench-test) which outputs into TAP format. I've modified the scripts slightly to cover CIS 1.13 instead of 1.11, but I don't know how to make Jenkins Pipeline handle that output. I know there is a Jenkins plugin for TAP format, but I don't believe this works with Jenkins Pipeline Groovy scripts. 回答1: @Grab will work only if you jenkins has access to the internet workspace/job_name/tap.groovy @Grab(group='org