jenkins-pipeline

Jenkins Workflow Multibranch allow for specifying Jenkinsfile path

≯℡__Kan透↙ 提交于 2020-01-13 08:21:09
问题 It seems like now you can only have a single Jenkinsfile in a single location in your project when using Multibranch type. Is there a way to configure so I can place the Jenkinsfile somewhere else than in the root of the project under the name Jenkinsfile. There's hope, as there's an option of Fixed Configuration, maybe this is a feature for the future, but I would much appreciate the option, as in the current situation I do not have the option to run everything as one nicely compiled

Create a file with some content using Groovy in Jenkins pipeline

限于喜欢 提交于 2020-01-13 07:36:09
问题 I am trying to create a file called groovy1.txt with the content "Working with files the Groovy way is easy." Note: I don't want to use the shell to create this file, instead I want to use Groovy to achieve this. I have following script in my Jenkins pipeline. node { def file1 = new File('groovy1.txt') file1.write 'Working with files the Groovy way is easy.\n' sh 'ls -l' // Expecting the file groovy1.txt should present with the content mentioned above } But it is throwing FileNotFound

Sync two git repositories Jenkins Pipeline

守給你的承諾、 提交于 2020-01-13 06:18:06
问题 I want to syncronize two repositories each time a build is been made, I have seen this script but I don't know how to set the remote branch with credentials too. # clone the reposotory git clone --bare $ORIGIN_URL # add a remote repository cd $REPO_NAME git remote add --mirror=fetch repo1 $REPO1_URL # update the local copy from the first repository git fetch origin --tags # update the local copy with the second repository git fetch repo1 --tags # sync back the 2 repositories git push origin -

Is it possible to make a parameterized scripted pipeline in Jenkins by listing the parameters in actual script, not in job config

烈酒焚心 提交于 2020-01-12 14:44:14
问题 In a declarative pipeline, I can specify the parameter that the pipeline expects right in the pipeline script like so: pipeline { parameters([ string(name: 'DEPLOY_ENV', defaultValue: 'TESTING' ) ]) } is it possible do to in a scripted pipline? I know I can do this : BUT, IS IT POSSIBLE TO DO THIS: node{ parameters([ string(name: 'DEPLOY_ENV', defaultValue: 'TESTING' ) ]) } 回答1: I found a solution by experimentation so want to share it: node { properties( [ parameters( [string(defaultValue: '

Is it possible to make a parameterized scripted pipeline in Jenkins by listing the parameters in actual script, not in job config

心不动则不痛 提交于 2020-01-12 14:42:51
问题 In a declarative pipeline, I can specify the parameter that the pipeline expects right in the pipeline script like so: pipeline { parameters([ string(name: 'DEPLOY_ENV', defaultValue: 'TESTING' ) ]) } is it possible do to in a scripted pipline? I know I can do this : BUT, IS IT POSSIBLE TO DO THIS: node{ parameters([ string(name: 'DEPLOY_ENV', defaultValue: 'TESTING' ) ]) } 回答1: I found a solution by experimentation so want to share it: node { properties( [ parameters( [string(defaultValue: '

How to throw exception in jenkins pipeline?

允我心安 提交于 2020-01-12 12:09:20
问题 I have handled the Jenkins pipeline steps with try catch blocks. I want to throw an exception manually for some cases. but it shows the below error. org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.IOException java.lang.String I checked the scriptApproval section and there is no pending approvals. 回答1: If you want to abort your program on exception, you can use pipeline step error to stop the pipeline execution with an error.

How to throw exception in jenkins pipeline?

烈酒焚心 提交于 2020-01-12 12:04:30
问题 I have handled the Jenkins pipeline steps with try catch blocks. I want to throw an exception manually for some cases. but it shows the below error. org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.IOException java.lang.String I checked the scriptApproval section and there is no pending approvals. 回答1: If you want to abort your program on exception, you can use pipeline step error to stop the pipeline execution with an error.

How to throw exception in jenkins pipeline?

你说的曾经没有我的故事 提交于 2020-01-12 12:02:16
问题 I have handled the Jenkins pipeline steps with try catch blocks. I want to throw an exception manually for some cases. but it shows the below error. org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.IOException java.lang.String I checked the scriptApproval section and there is no pending approvals. 回答1: If you want to abort your program on exception, you can use pipeline step error to stop the pipeline execution with an error.

How to define and iterate over map in Jenkinsfile

前提是你 提交于 2020-01-12 05:26:07
问题 My knowledge of groovy doesn't go very far beyond what little I know about Jenkinsfiles. I'm trying to figure out if it's possible to have a map defined in a Jenkinsfile that can then be applied in a "for loop" fashion. I have these variables: mymap = { "k1": "v1" "k2": "v2" "k3": "v3" } I have a stage in my Jenkinsfile that looks like this: stage('Build Image') { withCredentials([[<the credentials>]) { sh "make build KEY={k1,k2,k3} VALUE='{v1,v2,v3}'" } Is there a way to make a Build Image

Send email on jenkins pipeline failure

喜你入骨 提交于 2020-01-11 15:37:31
问题 How can i add to a jenkins pipeline an old-style post-build task which sends email when the build fails? I cannot find "Post-build actions" in the GUI for a pipeline. I know that i can wrap the entire build script try/catch, however this seems ugly when the build script is large and continues to send emails even when the job was aborted manually. I would like to achive the same functionality as with the previouse email-ext based post-build action. try { // Do sth } catch(e) { emailext body: '