Need to enable one task on BitBucket PullRequest created event

Issue #8 resolved
Saifuddin Tariwala created an issue

We have a static code analysis task which we need to enable only once PullRequest created event is been registered.

what groovy script to use?

Comments (9)

  1. Hutuleac Iulius repo owner

    Hi Tiriwala,

    I am afraid I am not aware of any method to distinguish triggering events at build level. The only thing that crosses my mind is to add one variable in bamboo saying pullrequest=false, usually in the groovy you would check it and disable the particular task, then in bitbucket use a hook to trigger the bamboo build and run it customized using the variable value set to true.

    In bitbucket you would use something like curl --data "bamboo.variable.BUILD_VERSION=684" http://host:8085/rest/api/latest/queue/BUILD-PLAN?os_authType=basic&os_username=...&os_password=...

    https://jira.atlassian.com/browse/BAM-5214

    Julius

  2. Saifuddin Tariwala reporter

    @iuliushutuleac

    So I defined one variable like : pullrequest = false under the plan configuration. Now, I am changing this variable to true when I queue up the build using CLI and defined a condition under

    Dynamic Tasks De-Activation: if (pullrequest) return "true";

    Task Matcher: .1.

    Expected results = whenever this variable value is changed to true it will disable the task match as "Task1". observed: but task still enabled

    Please let me know what is missing.

  3. Hutuleac Iulius repo owner

    Can you show me the binding section of the log (where it says groovy bindings) ? If is not visible you can switch org.valens to debug level.

    I suspect you have either a typo or variable is not available or we have wrong types.

    Please note I am passing the variables and their values as Strings to the groovy bindings so the right way to check would be the Java way, if (pullrequest.equals("true")) return true;

  4. Saifuddin Tariwala reporter

    so I changed the groovy script like you mentioned above:

    I have a Task1,

    Groovy Shell starting simple 09-Jan-2017 12:41:18 Groovy script if (pullrequest.equals("true")) return true; evaluated to [null] simple 09-Jan-2017 12:41:18 Skipping task [Task1] simple 09-Jan-2017 12:41:18 tasks list not set, skipping uild 09-Jan-2017 12:42:11 This task is still snabled simple 09-Jan-2017 12:42:11 Finished task 'Task1' with result: Success

    It ran the task even I specifically set the pull request variable to true, in order to disable the task1.

  5. Hutuleac Iulius repo owner

    evaluated to [null] instead of "true", that means something is wrong.

    Do you see a Groovy Binding ? It should look like this:

    DSL Processing starting... simple 09-Jan-2017 22:18:46 on ***** simple 09-Jan-2017 22:18:46 DSL Processing skipping: Checkout Default Repository - com.atlassian.bamboo.plugins.vcs:task.vcs.checkout simple 09-Jan-2017 22:18:46 DSL Processing skipping: Deploy basic service - com.valens.bamboo.ansible.bamboo-ansible-task:ansiblePlayTask simple 09-Jan-2017 22:18:46 GroovyShell bindings: simple 09-Jan-2017 22:18:46 groovyVariableName=TASKS_DISABLE_PER_BRANCH simple 09-Jan-2017 22:18:46 DISABLE_UNUSED_PACKAGES=|NoPackagesDoDisable simple 09-Jan-2017 22:18:46 GRADLE_OPTS= simple 09-Jan-2017 22:18:46 DISABLE_VNC_SERVER_TASKS=|. VNC . simple 09-Jan-2017 22:18:46 JAVA_SOURCE=source simple 09-Jan-2017 22:18:46 hosts= simple 09-Jan-2017 22:18:46 extravars= simple 09-Jan-2017 22:18:46 MAVEN_OPTS=-U simple 09-Jan-2017 22:18:46 HOSTS=all simple 09-Jan-2017 22:18:46 ANSIBLE_COMMON_ARGS=--vault-password-file ~/ansible-vault-pass -v simple 09-Jan-2017 22:18:46 GRADLE_SOURCE=source simple 09-Jan-2017 22:18:46 DISABLE_MONGO_TASKS_MASK=|.Mongo. simple 09-Jan-2017 22:18:46 SOURCE=source simple 09-Jan-2017 22:18:46 TASKS_DISABLE_PER_BRANCH=script: def mask=".master.|.develop."; try{ if (repository_git_branch_0.equalsIgnoreCase("master")) mask=".develop.|.feature."; if (repository_git_branch_0.equalsIgnoreCase("develop") || repository_git_branch_0.equalsIgnoreCase("feature.integrated.")) mask=".master.|.feature."; }catch(Throwable e){}; try{ if (repository_stash_branch_0.equalsIgnoreCase("master")) mask=".develop.|.feature."; if (repository_stash_branch_0.equalsIgnoreCase("develop") || repository_stash_branch_0.equalsIgnoreCase("feature.integrated.")) mask=".master.|.feature.*"; }catch(Throwable e){}; return mask;

  6. Saifuddin Tariwala reporter

    yes, I can see the groovy binding. Sorry, My mistake, actually my global bamboo plan variable default value is overridden by branch level variable settings. After I corrected it, I see:

    simple 09-Jan-2017 13:25:43 GroovyShell bindings: simple 09-Jan-2017 13:25:43 groovyVariableName=Condition simple 09-Jan-2017 13:25:43 pullrequest=true simple 09-Jan-2017 13:26:45 Skipping execution of task 'Task1' as it is disabled

    So, meaning the task successfully got disabled.

    Thanks, -Saif

  7. Hutuleac Iulius repo owner

    No problem, glad to hear you got it started. First one is the hardest, after this I am sure you will sale smooth.

    Best regards, Julius

  8. Log in to comment