jenkins-pipeline

Trigger hourly build from scripted Jenkinsfile

 ̄綄美尐妖づ 提交于 2019-11-30 06:46:56
问题 Is there a way to trigger a Jenkins job to run every hour using the Jenkinsfile scripted pipeline syntax? I have seen examples using the declarative syntax, but none using the pipeline syntax. Declarative Syntax Example pipeline { agent any triggers { cron '@daily' } ... } 回答1: You could use this snippet for Scripted pipeline syntax : properties( [ ... , // other properties that you have pipelineTriggers([cron('0 * * * *')]), ] ) Reference for properties is here. You can search for

Set the build name and description from a Jenkins Declarative Pipeline

一个人想着一个人 提交于 2019-11-30 06:14:19
I would like to set the build name and description from a Jenkins Declarative Pipeline, but can't find the proper way of doing it. I tried using an environment bracket after the pipeline, using a node bracket in an agent bracket, etc. I always get syntax error. The last version of my Jenkinsfile goes like so: pipeline { stages { stage("Build") { steps { echo "Building application..." bat "%ANT_HOME%/bin/ant.bat clean compile" currentBuild.name = "MY_VERSION_NUMBER" currentBuild.description = "MY_PROJECT MY_VERSION_NUMBER" } } stage("Unit Tests") { steps { echo "Testing (JUnit)..." echo

Hiding password in Jenkins pipeline script

无人久伴 提交于 2019-11-30 05:58:12
I'm trying to mask a password in my Jenkins build. I have been trying the mask-passwords plugin . However, this doesn't seem to work with my Jenkins pipeline script, because if I define the password PASSWD1 and then I use it in the script like this ${PASSWD1} , I am getting: No such DSL method '$' found among steps [addToClasspath, ansiColor, ansiblePlaybook, ....] If I use env.PASSWD1 , then its value will be resolved to null . So how should I mask a password in a Jenkins pipeline script? Christopher Orr The simplest way would be to use the Credentials Plugin . There you can define different

How to mount Jenkins workspace in docker container using Jenkins pipeline

两盒软妹~` 提交于 2019-11-30 05:22:15
I'm using Jenkins in docker. The /var/jenkins_home is mounted on /var/jenkins-data on my host. My Jenkins can execute docker commands (mount of sockets) and I've installed the git plugin and pipeline plugin. Now I have a pipeline job named test and the following pipeline: pipeline { agent any stages { stage('Clone') { steps { git branch: 'master', url: 'https://github.com/lvthillo/maven-hello-world.git' } } stage('Build in Docker') { agent { docker { image 'maven:3.5.2' args '-v /var/jenkins_home/workspace/test:/opt/maven -w /opt/maven' } } steps { sh 'pwd' sh 'mvn -v' sh 'mvn clean install' }

Try-catch block in Jenkins pipeline script

房东的猫 提交于 2019-11-30 05:05:47
I'm trying to use the following code to execute builds, and in the end, execute post build actions when builds were successful. Still, I get a MultipleCompilationErrorsException, saying that my try block is Not a valid section definition. Please help, I tried a lot reorganize the block but can't seem to be able to solve the issue. #!/usr/bin/env groovy pipeline{ agent any try { stages{ stage("Parallel 1") { steps { parallel ( 'firstTask' : { build( "DSL-Controll-Demo-Fibonacci-1" ) }, 'secondTask' : { build( "DSL-Controll-Demo-Fibonacci-2" ) } ) } } stage("Feature") { steps { build( "DSL

Get username logged in Jenkins from Jenkins Workflow (Pipeline) Plugin

被刻印的时光 ゝ 提交于 2019-11-30 04:59:10
I am using the Pipeline plugin in Jenkins by Clouldbees (the name was Workflow plugin before), I am trying to get the user name in the Groovy script but I am not able to achieve it. stage 'checkout svn' node('master') { // Get the user name logged in Jenkins } Did you try installing the Build User Vars plugin ? If so, you should be able to run node { wrap([$class: 'BuildUser']) { def user = env.BUILD_USER_ID } } or similar. YourAboutMeIsBlank To make it work with Jenkins Pipeline: Install user build vars plugin Then run the following: pipeline { agent any stages { stage('build user') { steps {

Job DSL to create “Pipeline” type job

徘徊边缘 提交于 2019-11-30 04:42:47
I have installed Pipeline Plugin which used to be called as Workflow Plugin earlier. https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin I want to know how can i use Job Dsl to create and configure a job which is of type Pipeline You should use pipelineJob : pipelineJob('job-name') { definition { cps { script('logic-here') sandbox() } } } You can define the logic by inlining it: pipelineJob('job-name') { definition { cps { script(''' pipeline { agent any stages { stage('Stage 1') { steps { echo 'logic' } } stage('Stage 2') { steps { echo 'logic' } } } } } '''.stripIndent()) sandbox() }

How to get svn version number from checkout for use in dsl

会有一股神秘感。 提交于 2019-11-30 04:40:05
问题 I created a pipeline job and would like to get the svn version number to enable further downstream processing in a call to a shell script. I am using a pipeline script similar to the following: node { // Mark the code checkout 'stage'.... stage 'Checkout' // Get some code from a SVM repository checkout( [ $class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges:

Is it possible to disable [Pipeline] messages in Jenkins pipeline console output?

空扰寡人 提交于 2019-11-30 04:36:55
问题 I am working on some particular Jenkins pipeline which has many steps included - most of which are written in Groovy - because of that I am seeing many [Pipeline] messages which are totally unimportant and unnecessary for me. Is it possible to suppress those? I am asking for something similiar as in related question 2. but I would like to supress all [Pipeline] messages - which includes messages like: [Pipeline] node [Pipeline] { [Pipeline] stage [Pipeline] { (Test) [Pipeline] bat [Pipeline]

How can I block a Jenkins 2.x Pipeline job while dependent jobs are building

依然范特西╮ 提交于 2019-11-30 04:31:17
问题 My question is fairly straightforward: With a Freestyle Jenkins project under "Advance Project Options" I can select two configuration options that help prevent conflicts between different projects (that may arise e.g. when one project updates a set of header files while another project is including these): Block build when upstream project is building Block build when downstream project is building For a Pipeline or Multibranch project these configuration options are unavailable, and I am