jenkins-workflow

Sandbox is preventing me from formatting a string

為{幸葍}努か 提交于 2019-12-01 06:22:36
I have a simple groovy script: node ("master") { echo "I am about to try to use String.format" def jjj = String.format("bob") echo jjj } If I put this script right into my job configuration and run it, it runs fine. But if I put that script into a file which I then load via "Workflow script from SCM", I get the error org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified staticMethod java.lang.String format java.lang.String How do I work around this? Is it possible to turn off the sandbox for "Workflow script from SCM" like it is for "Workflow script"? Or is there

Jenkins building a product consisting of many Maven projects? (with Jenkins Pipeline plugin?)

牧云@^-^@ 提交于 2019-11-30 12:36:56
问题 We have a product that consists of many Maven projects that depend on each other. All of these Maven projects come together in a single project which delivers the end product. The Maven projects share the same life cycle. In other words, they are not managed by separate teams of people with explicit <dependency> changes to pick up newer versions of other projects. Rather, when someone changes something in one of the projects, then the result should go directly into the end product without

Jenkins Pipeline accessing environment variables

夙愿已清 提交于 2019-11-30 11:51:22
问题 I'm trying to use DSL pipelines in Jenkins. I thought it'd be nice if I could use the project name as part of my script. git credentialsId: 'ffffffff-ffff-ffff-ffff-ffffffffffffff',\ url: "${repo_root}/${JOB_NAME}.git" I get the error: groovy.lang.MissingPropertyException: \ No such property: JOB_NAME for class: groovy.lang.Binding I thought I followed these directions, and they mention JOB_NAME as one of the variables. I decided to try: sh 'env' in my DSL, and this prints out: JOB_NAME = foo

How to perform actions for failed builds in Jenkinsfile

这一生的挚爱 提交于 2019-11-30 11:48:28
Is there a way to perform cleanup (or rollback) if the build in Jenkinsfile failed? I would like to inform our Atlassian Stash instance that the build failed (by doing a curl at the correct URL). Basically it would be a post step when build status is set to fail. Should I use try {} catch () ? If so, what exception type should I catch? I'm currently also searching for a solution to this problem. So far the best I could come up with is to create a wrapper function that runs the pipeline code in a try catch block. If you also want to notify on success you can store the Exception in a variable

Accessing SCM (Git) variables on a Jenkins Pipeline job [duplicate]

不问归期 提交于 2019-11-30 08:03:36
This question already has an answer here: Git Variables in Jenkins Workflow plugin 7 answers Here's my pipeline code: node ('master') { git url: "$GIT_REPO_URL", branch: "$GIT_BRANCH" echo env.GIT_COMMIT echo env.GIT_BRANCH echo env.GIT_REVISION } The build results looks like: Started by user anonymous [Pipeline] Allocate node : Start Running on master in /var/lib/jenkins/jobs/test/workspace [Pipeline] node { [Pipeline] git > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://acme/scm/app.git # timeout=10

How do I tag the current git changeset from inside the Jenkinsfile?

匆匆过客 提交于 2019-11-30 07:09:28
I want to tag the current git changeset and push the tag from inside the Jenkinsfile. If the tag already exists it must be replaced. I want to use this logic in order to tag the build that passed with the snapshot tag, which would be a mobile tag. How can I do this? sorin Here is the way I was able to implement this this way, but if you know a better way I am more than willing to hear it. #!groovy stage 'build' node { repositoryCommiterEmail = 'ci@example.com' repositoryCommiterUsername = 'examle.com' checkout scm sh "echo done" if (env.BRANCH_NAME == 'master') { stage 'tagging' sh("git config

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() }

Jenkins building a product consisting of many Maven projects? (with Jenkins Pipeline plugin?)

喜欢而已 提交于 2019-11-30 03:09:35
We have a product that consists of many Maven projects that depend on each other. All of these Maven projects come together in a single project which delivers the end product. The Maven projects share the same life cycle. In other words, they are not managed by separate teams of people with explicit <dependency> changes to pick up newer versions of other projects. Rather, when someone changes something in one of the projects, then the result should go directly into the end product without additional changes. We use Jenkins as our Continuous Integration tool. The main wishes we have are as

How can I perform HTTP POST requests from within a Jenkins Groovy script?

喜你入骨 提交于 2019-11-30 00:48:21
问题 I need to be able to create simple HTTP POST request during our Jenkins Pipeline builds. However I cannot use a simple curl sh script as I need it to work on Windows and Linux nodes, and I don't wish to enforce more tooling installs on nodes if I can avoid it. The Groovy library in use in the Pipeline plugin we're using should be perfect for this task. There is an extension available for Groovy to perform simple POSTs called http-builder, but I can't for the life of me work out how to make

Jenkins Build Periodically - Schedule

余生颓废 提交于 2019-11-29 14:06:11
I am looking to build periodically every 15 minutes. I have looked online and I am using this schedule: */15 * * * * Jenkins is telling me to spread load evenly by using H/15 * * * * rather than */15 * * * * Could someone tell me the difference between using H instead of * ? Avihoo Mamka Yes. From the Build Triggers → Build periodically → Schedule → inline help: To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible. For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast