jenkins-workflow

How do I use Jenkins Pipeline properties step?

会有一股神秘感。 提交于 2019-11-28 07:09:14
I am studying capabilities of Jenkins Pipeline:Multibranch. It is said that a recently introduced properties step might be useful there, but I can't catch how it works and what is its purpose. Its hint message doesn't seem to be very clear: Updates the properties of the job which runs this step. Mainly useful from multibranch workflows, so that Jenkinsfile itself can encode what would otherwise be static job configuration. So I created a new Pipeline with this as a script (pasted directly into Jenkins not in SCM): properties [[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[

How to implement Post-Build stage using Jenkins Pipeline plug-in?

夙愿已清 提交于 2019-11-28 06:10:38
After reading Jenkins tutorial explaining Pipeline plug-in, it seems that plug-in should make it possible to implement Post-Build steps. However documentation is rather limited in regard to specific instructions. For example I wonder how to implement: Run only if build succeeds Run only if build succeeds or is unstable Run regardless of build result Run only if build succeeds stage 'build' ... build ... tests stage 'post-build' ... (Or add -Dmaven.test.failure.ignore=false to the MAVEN_OPTS ) Run only if build succeeds or is unstable stage 'build' ... build try { ... tests } catch { ... }

Retrieve all properties of env in Jenkinsfile

不羁的心 提交于 2019-11-28 03:00:36
问题 I would like to print all available properties (and their values) in env object inside Jenkinsfile. When I do print env I get: org.jenkinsci.plugins.workflow.cps.EnvActionImpl@112cebc2 So it looks like toString is not implemented there, how can I access properties that are in this object if I don't know their names? 回答1: Make sure you're not running the pipeline script in sandboxed mode and you should be able to use: env.getEnvironment() Note, if you're running in sandbox mode in a pipeline,

How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)?

百般思念 提交于 2019-11-27 22:45:59
I am trying to find an example of using the Jenkins Copy Artifacts Plugin from within Jenkins pipelines (workflows). Can anyone point to a sample Groovy code that is using it? If builds are not running in the same pipeline you can use direct CopyArtifact plugin, here is example: https://www.cloudbees.com/blog/copying-artifacts-between-builds-jenkins-workflow and example code: node { // setup env.. // copy the deployment unit from another Job... step ([$class: 'CopyArtifact', projectName: 'webapp_build', filter: 'target/orders.war']); // deploy 'target/orders.war' to an app host } With a

How do I prevent two pipeline jenkins jobs of the same type to run in parallel on the same node?

耗尽温柔 提交于 2019-11-27 18:27:44
I want not to allow two jobs of the same type (same repository) not to run in parallel on the same node. How can I do this using groovy inside Jenkinsfile? hypery2k You got at the disableConcurrentBuilds property: properties properties: [ ... disableConcurrentBuilds(), ... ] Then the job would wait the older one to finish first The answer provided in https://stackoverflow.com/a/43963315/6839445 is deprecated. The current method to disable concurrent builds is to set options: options { disableConcurrentBuilds() } Detailed description is available here: https://jenkins.io/doc/book/pipeline

Check if a file exists in jenkins pipeline

冷暖自知 提交于 2019-11-27 17:04:57
问题 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? 回答1: 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

How can I trigger another job from a jenkins pipeline (jenkinsfile) with GitHub Org Plugin?

五迷三道 提交于 2019-11-27 16:58:49
How can I trigger build of another job from inside the Jenkinsfile ? I assume that this job is another repository under the same github organization , one that already has its own Jenkins file. I also want to do this only if the branch name is master, as it doesn't make sense to trigger downstream builds of any local branches. Update: stage 'test-downstream' node { def job = build job: 'some-downtream-job-name' } Still, when executed I get an error No parameterized job named some-downtream-job-name found I am sure that this job exists in jenkins and is under the same organization folder as the

Tag a Repo from a Jenkins Workflow Script

梦想与她 提交于 2019-11-27 15:57:55
问题 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? 回答1: I've managed to get this working by using the withCredentials step provided by the credentials binding plugin. Its not great because it involved

Get absolute path to workspace directory in Jenkins Pipeline plugin

ⅰ亾dé卋堺 提交于 2019-11-27 15:26:11
I'm currently doing some evaluation on the Jenkins Pipeline plugin (formerly know as Workflow plugin). Reading the documentation I found out that I currently cannot retriev the workspace path using env.WORKSPACE : The following variables are currently unavailable inside a workflow script: NODE_LABELS WORKSPACE SCM-specific variables such as SVN_REVISION Is there any other way how to get the absolute path to the current workspace? I need this running some test which in turn gets some parameter (absolute path to some executable file). I already tried using new File("").absolutePath() inside a

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

落爺英雄遲暮 提交于 2019-11-27 14:18:23
问题 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 回答1: 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 回答2: I'm just putting a '\' on the end of