jenkins-workflow

How can I disable security checks for Jenkins pipeline builds

早过忘川 提交于 2019-11-29 09:51:52
I'm running Jenkins in a local trusted environment where I'm trying to run this pipeline. This Jenkinsfile is checked into git. #!groovy node('master') { def ver = pomVersion() echo "Building version $ver" } def pomVersion(){ def pomtext = readFile('pom.xml') def pomx = new XmlParser().parseText(pomtext) pomx.version.text() } The first few times I ran the build, I needed to manually approve changes (Jenkins->Mange Jenkins-> In-process Script Approval). Now I get this Exception and there is nothing to approve. All I want to do is parse an XML file. Can these security checks be bypassed

Initializing Jenkins 2.0 with pipeline in init.groovy.d script

我的未来我决定 提交于 2019-11-29 09:42:59
问题 For automation, I would like to initialize a Jenkins 2.0 instance with a pipeline job. I want to create a Groovy script that is copied to the /usr/share/jenkins/ref/init.groovy.d/ folder on startup. The script should create a Jenkins 2.0 Pipeline job for processing a Jenkinsfile from SCM. I cannot find the relevant Javadoc for the 2.0 pipeline classes or examples of how to do this. Previously, using Job DSL to create a pipeline, I used a Groovy script to create a FreeStyleProject with an

Check if a file exists in jenkins pipeline

丶灬走出姿态 提交于 2019-11-29 05:23:51
I am trying to run block if a directory exists in my jenkins workspace and the pipeline step "fileExists: Verify file exists" in workspace doesn't seem to work correctly. I'm using Jenkins v 1.642 and Pipeline v 2.1. and trying to have a condition like if ( fileExists 'test1' ) { //Some block } What are the other alternatives I have within pipeline? You need to use brackets when using the fileExists step in an if condition or assign the returned value to a variable Using variable: def exists = fileExists 'file' if (exists) { echo 'Yes' } else { echo 'No' } Using brackets: if (fileExists('file'

Tag a Repo from a Jenkins Workflow Script

≯℡__Kan透↙ 提交于 2019-11-29 01:40:58
I'm currently trying to tag a repo from a Jenkins Workflow script. I've tried using a sh step but this runs into problems because of credentials not being set. fatal: could not read Username for 'https://<repo>': Device not configured Is there an existing step that can be used either to tag a repo or to get round the credentials problem? I've managed to get this working by using the withCredentials step provided by the credentials binding plugin. Its not great because it involved specifying it all in the URL but these values are masked in the console output. withCredentials([[$class:

Job DSL to create “Pipeline” type job

狂风中的少年 提交于 2019-11-28 22:28: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 回答1: 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')

How to set variables in a multi-line shell script within Jenkins Groovy?

让人想犯罪 __ 提交于 2019-11-28 22:19:53
Suppose I have a Groovy script in Jenkins that contains a multi-line shell script. How can I set and use a variable within that script? The normal way produces an error: sh """ foo='bar' echo $foo """ Caught: groovy.lang.MissingPropertyException: No such property: foo for class: groovy.lang.Binding You need to change to triple single quotes ''' or escape the dollar \$ Then you'll skip the groovy templating which is what's giving you this issue I'm just putting a '\' on the end of line sh script: """\ foo='bar' \ echo $foo \ """, returnStdout: true This statement works on my script. 来源: https:/

Start a job multiple times concurrently with workflow plugin

家住魔仙堡 提交于 2019-11-28 22:01:55
I am trying to run one job 5 times concurrently using the workflow plugin. here is the snippet: def concurrent=[:] for (int i = 0; i < 5; i++) { concurrent["concurrent${i}"] = { build job: 'test_job', parameters: [[$class: 'StringParameterValue', name:'queue', value: 'automation_prod.q'],[$class: 'StringParameterValue', name:'dummy', value: "${i}"]] } } parallel concurrent this snippet causes the the test_job to run only once. I need it running 5 times concurrently. thanks! There is no bug in Workflow here beyond a lack of diagnosis for the mistake in the script. In Groovy, the loop counter i

Jenkins: Trigger Multi-branch pipeline on upstream change

大憨熊 提交于 2019-11-28 17:35:01
I am currently testing the pipeline approach of Jenkins 2.0 to see if it works for the build environment I am using. First about the environment itself. It currently consists of multiple SCM repositories. Each repository contains multiple branches, for the different stages of the development and each branch is build with multiple configurations. Not all configurations apply to every repository. Currently every repository/branch is setup as a Matrix Project for the different configurations. Each project exposes it's building results as a artifact and these artifacts are used in the downstream

How can I test a change made to Jenkinsfile locally?

时光怂恿深爱的人放手 提交于 2019-11-28 13:42:33
问题 When writing jenkins pipelines it seems to be very inconvenient to commit each new change in order to see if it works. Is there a way to execute these locally without committing the code? 回答1: You cannot execute Pipeline script locally, since its whole purpose is to script Jenkins. (Which is one reason why it is best to keep your Jenkinsfile short and limited to code which actually deals with Jenkins features; your actual build logic should be handled with external processes or build tools

Jenkins Workflow Checkout Accessing BRANCH_NAME and GIT_COMMIT

北城余情 提交于 2019-11-28 08:25:05
I cannot seem to extract $GIT_COMMIT and $BRANCH_NAME from a Jenkins Workflow Checkout step. I would like to be able to send this information through to my Gradle scripts in order to pass it onto external sources such as Static analysis etc. Currently I try to run this: checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[credentialsId: '2b74a351-67d5-4d00-abd3-49842a984201', url: 'ssh://git@corporate.com:repo.git']]]) And I would like to achieve the following or something similar: // Specified variables that can be reused def branch = ${BRANCH_NAME} def commit = $