Dynamic Plans and DSL Plugin for Bamboo

Dynamic scripted variables:

- any variable containing the following pattern will be calculated script: if (repository_git_branch_0.equalsIgnoreCase("master")) return "true";


Conditioned scripted jobs

Dynamic Tasks De-Activation

On each job you can enter a groovy that will be evaluated.

If return is "true" some tasks having a description matching a configurable regular expression will be disabled.

Dynamic Tasks Switcher

On each job you can enter a groovy that will be evaluated and should return a regular expression

Any task having a description matching this regular expression will be set accordingly to your request.

Eg:

Assuming we have 3 tasks in our plan:
  • develop
  • master
  • feature

We can use the following groovy script that will return expressions to match the tasks based on which is the current branch.

if (repository_git_branch_0.equalsIgnoreCase("master")) 
     return "master"; 
if (repository_git_branch_0.equalsIgnoreCase("develop")) 
     return "develop"; return "feature"; 
if (repository_git_branch_0.equalsIgnoreCase("develop")) 
     return "develop"; 
return "feature";

If in the settings we have placed Desired state as Enabled the plugin will tend to enable each task when branch is switching.



DSL Tasks (from version 3.0.1)

The DSL tasks are using a groovy based language with few predefined "keywords":
  • define "myVar","develop" - will define a new variable to be used in the job
  • append <build job key> - will read all tasks from the job mentioned and append them to the current job
  • task <plugin key>,<configuration map> - will append a new task to the current job
  • finaltask <plugin key>,<configuration map> - will append a new final task to the current job
Processing is not actually performed by the task itself, a prebuild phase is responsible for parsing and executing the content in the task.


Sample task:

System.out.println("Hello");

append "TEMPLATE-BUILD-JOB1";

if (repository_svn_repositoryUrl_0.contains("trunk"))
     define "myVar","develop" 
else
     define "myVar","other"

task 'com.atlassian.bamboo.plugins.scripttask:task.builder.script',
[
'argument':'',
'scriptLocation':'INLINE',
'environmentVariables':'',
'runWithPowershell':'',
'scriptBody':'echo This task was added dynamic',
'script':'',
'workingSubDirectory':'',
]

finaltask 'org.jfrog.bamboo.bamboo-artifactory-plugin:artifactoryGenericTask',
[
'artifactory.generic.publishBuildInfo':'true',
'bintrayConfiguration':'',
'bintray.licenses':'',
'bintray.repository':'',
'artifactory.generic.username':'',
'bintray.packageName':'',
'artifactory.generic.includeEnvVars':'',
'artifactory.generic.artifactSpecs':'',
'artifactory.generic.password':'',
'bintray.mavenSync':'',
'artifactory.generic.resolveRepo':'',
'baseUrl':'http://bamboo.myhost.net:8085',
'artifactory.generic.envVarsIncludePatterns':'',
'artifactory.generic.resolvePattern':'',
'bintray.vcsUrl':'',
'builder.artifactoryGenericBuilder.deployableRepo':'maven-release-local',
'artifactory.generic.deployPattern':'*.npm',
'artifactory.generic.envVarsExcludePatterns':'*password*,*secret*',
'bintray.signMethod':'false',
'bintray.gpgPassphrase':'',
'builder.artifactoryGenericBuilder.artifactoryServerId':'0',
'bintray.subject':'',
]



DSL Code Generator


In the administration page under the addons menu you will be able to locate the DSL Generator, is not perfect but it should get you started. The generator will allow you to pick a job and reverse engineer.



Running DSL without a task

While running some DSL in a task might be useful sometimes some other times it would be useful to store this configuration next to the source code. As of version 3.0.6 this is possible - create a file in your repository named bamboo.dsl.buildconfig and make sure it is being checked out at the root of working folder (this can be changed using Misc configuration tab of the job).

As part of the pre-build phase bamboo will load and execute the file !





7 comments:

  1. No examples for "Dynamic Tasks De-Activation" - just a screenshot of an empty form. Can you elaborate on how I use this plugin?

    ReplyDelete
    Replies
    1. Quite simple actually:

      Assume you have 2 tasks in your job: "Task 1" and "Task 2" and on master branch you dont want to run "Task 1"

      Fill under condition the following: if (repository_git_branch_0.equalsIgnoreCase("master")) return "true";
      Fill under task matcher: .*1.*

      Run and you get:

      26-Sep-2016 18:14:16 Groovy Shell starting
      26-Sep-2016 18:14:16 Groovy script if (repository_git_branch_0.equalsIgnoreCase("master")) return "true"; evaluated to [true]
      26-Sep-2016 18:14:16 Disabling task [task 1]
      26-Sep-2016 18:14:16 tasks list not set, skipping
      26-Sep-2016 18:14:16 Skipping execution of task 'task 1' as it is disabled
      26-Sep-2016 18:14:16 Starting task 'task 2' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'

      I use for example with deployments of artifacts to Nexus & Artifactory. I have a task deploying on a release repository and a secondary task deploying on a snapshot repository. On master I disable deploy to snapshot, on develop I disable deploy to release, on feature branches I disable all deployments.

      Delete
    2. In case you wonder why I have similar functionalities in Dynamic Tasks Switcher, the task switcher is more flexible can enable/disable but I had already released the previous section of the plugin so I kept it for backwards compatibility last year.

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Can we set the build result to true after a task is disabled via your plugin ? Thank you

    ReplyDelete
    Replies
    1. The plugin cannot change the build result, it can disable tasks on the fly so they are not executed at all. For example you can run a deploy to maven from master branch or disable the deployment on other branches, or trigger compile with different flags based on some agent specific setup.

      Delete
  4. Anonymous12/14/2017

    We are trying your plugin in order to buy some licenses, but we have found that sometimes our builds hangs a couple of minutes waiting for some kind of checking:

    simple 13-Dec-2017 18:14:08 conditions not set, skipping
    simple 13-Dec-2017 18:14:08 tasks list not set, skipping
    simple 13-Dec-2017 18:16:32 Here the build starts

    Any ideas?

    ReplyDelete