jenkins-pipeline

Migrate from Jenkins Multijob to Pipeline plug-in

与世无争的帅哥 提交于 2019-12-10 13:37:36
问题 Currently we are using Jenkins CI 1.643 (I believe) with the Multijob plugin and Job DSL. A collection of jobs is generated using Job DSL, as well as a multijob that contains all the other jobs in a specific order (build, analysis, unit test, integration test, etc.). I'm interested in upgrading to Jenkins 2 and using the Pipeline plug-in (previously known as the Workflow plug-in). The Pipeline plug-in offers a nice graphical representation and also offers some more advanced features that we

Run stage only if previous stage was successful in Jenkins Scripted Pipeline

落花浮王杯 提交于 2019-12-10 13:27:04
问题 I am trying to run conditional steps in a Jenkins scripted pipeline, however I am not sure how to only run a step if a previous step was successful. For instance, in the following I only want to run the 'Push Artifacts' stage if the 'Test' stage was successful: node ('docker2') { stage ('Build') { // build application } stage ('Test') { // run tests } stage ('Push Artifacts') { if (Tests Were Successful) { // push to artifactory } } } I know that declarative pipelines allow you to use 'post'

How to send “back to normal” notifications in Jenkins Declarative Pipeline?

為{幸葍}努か 提交于 2019-12-10 13:18:54
问题 I'm trying to convert an existing Jenkins Pipeline to the new Declarative Pipeline and I was wondering how to handle correctly mail notifications ? I'm currently using this code: node { try { ... currentBuild.result = 'SUCCESS' } catch (any) { currentBuild.result = 'FAILURE' throw any } finally { step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "baptiste.wicht@gmail.com", sendToIndividuals: true]) } } It works well, but I don't see how to use the new declarative syntax for

How to handle nightly build in Jenkins declarative pipeline

亡梦爱人 提交于 2019-12-10 13:01:58
问题 I have a multibranch pipeline with a Jenkinsfile in my repo and I am able to have my CI workflow (build & unit tests -> deploy-dev -> approval -> deploy-QA -> approval -> deploy-prod) on every commit. What I would like to do is add SonarQube Analysis on nightly builds in the first phase build & unit tests. Since my build is triggerd by Gitlab I have defined my pipeline triggers as follow : pipeline { ... triggers { gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType:

Proper configuring of Multibranch Pipeline in Jenkins

怎甘沉沦 提交于 2019-12-10 12:45:03
问题 How do I properly configure a Multibranch Pipeline in Jenkins when Git is selected as branch source? I get a "Does not meet criteria" for every branch that is checked in the branch indexing log. 回答1: This Multibranch Pipeline job will create a pipeline job if your Git branch contains a Jenkinsfile. This Jenkinsfile describe how to build the current branch (Jenkins Groovy DSL). If your branch doesn't contain a Jenkinsfile, then you will get this "does not meet criteria" message. More

How to get the latest commit messages within a push and verify the message start with a certain regex pattern?

ε祈祈猫儿з 提交于 2019-12-10 11:55:21
问题 I have two questions 1. Try to parse for git commit messages, but the egrep execute as a separate command. The return result is always incorrect. The valid message can be "a-1" stage('test') { steps { script { def result = sh(script: "git log -1 --pretty=%B | egrep '(([a-zA-Z ]+-\\d+[, \t\n]*)+)(.*)'", returnStatus: true) if (result == 0) { echo "continuous building..." } else { echo "Incorrect commit message prefix. Aborting" exit 1 } } } } Run result. Here it shows processor has separated

Git command to checkout latest commit from develop branch

末鹿安然 提交于 2019-12-10 11:35:24
问题 Using groovy syntax in Jenkins pipeline, below is the syntax used for check out: git branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git" Where credential is jenkins credential( 111111-222222-33333-44444 ) shown below: jenkins does the following under the hood, for groovy syntax(above): Cloning the remote Git repository Cloning repository ssh://git@10.xx.xx.xx:2222/abc/def.git > git init /app/jenkins/workspace/../def # timeout=10 Fetching upstream

Windows START command not working from Jenkins Pipeline

半城伤御伤魂 提交于 2019-12-10 11:17:55
问题 I have following code in my script. echo Trying to kill all node processes. taskkill /f /im node.exe echo Running the application... start npm run prod echo Success... The script runs fine if I open a command prompt and run it from there but it doesn't start the npm run process when I run it from Jenkins pipeline. Strange thing is the build gets success. Can anyone help me solve this riddle? Thanks. Update - 1 This is the output in Jenkins. up to date in 23.58s [Pipeline] } [Pipeline] //

How to build and get build log of pipeline job by another pipeline job in jenkins

…衆ロ難τιáo~ 提交于 2019-12-10 10:39:53
问题 I'm using Jenkins pipeline. I can build and get build log of the job by command: def itemA = hudson.model.Hudson.instance.getItem(FOLDER).getJob(JOB_NAME_A) hudson.model.Hudson.instance.queue.schedule(itemA) def buildObj = itemA.getLastBuild() def log = buildObj.log It's OK. But if JOB_NAME_A is a pipeline job, I get an error: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method hudson.model.Queue schedule org.jenkinsci.plugins.workflow.job.WorkflowJob at

Passing variables to powershell script block in a jenkins pipeline

依然范特西╮ 提交于 2019-12-10 10:23:52
问题 Is there a way to use groovy variables inside a powershell script? My sample script is as following.. node { stage('Invoke Installation') { def stdoutpowershell def serverName = env.fqdn withEnv(['serverName = $serverName']) { echo "serverName : $serverName" stdoutpowershell = powershell returnStdout: true, script: ''' write-output "Server is $env:serverName" ''' } } 回答1: You can't interpolate variables in single quotes or triple-single-quotes. Use triple-double-quotes: stdoutpowershell =