Variable scripting example does not work

Create issue
Issue #3 resolved
Former user created an issue

The example variable scripting obviously does not work.

 script:  if (repository_git_branch_0.equalsIgnoreCase("master")) return "publish" else return "preview";

Evaluates for a branch plan as follows:

07-Dez-2015 16:34:09    GroovyShell bindings:
07-Dez-2015 16:34:09        groovyVariableName=sonar_analysis_mode
07-Dez-2015 16:34:09        bambooDelimiterParsingDisabled_0=true
07-Dez-2015 16:34:09        filter_pattern_option_0=none
07-Dez-2015 16:34:09        filter_pattern_regex_0=
07-Dez-2015 16:34:09        changeset_filter_pattern_regex_0=
07-Dez-2015 16:34:09        repository_common_quietPeriod_enabled_0=false
07-Dez-2015 16:34:09        repository_common_quietPeriod_period_0=10
07-Dez-2015 16:34:09        repository_common_quietPeriod_maxRetries_0=5
07-Dez-2015 16:34:09        repository_git_repositoryUrl_0=xxx
07-Dez-2015 16:34:09        repository_git_branch_0=master
07-Dez-2015 16:34:09        repository_git_useShallowClones_0=true
07-Dez-2015 16:34:09        repository_git_useRemoteAgentCache_0=false
07-Dez-2015 16:34:09        repository_git_useSubmodules_0=false
07-Dez-2015 16:34:09        repository_git_commandTimeout_0=180
07-Dez-2015 16:34:09        repository_git_verbose_logs_0=false
07-Dez-2015 16:34:09        repository_git_fetch_whole_repository_0=false
07-Dez-2015 16:34:09        repository_git_sharedCrendentials_0=103120897
07-Dez-2015 16:34:09        repository_git_authenticationType_0=SHARED_CREDENTIALS
07-Dez-2015 16:34:09        selectedWebRepositoryViewer_0=bamboo.webrepositoryviewer.provided:noRepositoryViewer
07-Dez-2015 16:34:09    Groovy Shell starting
07-Dez-2015 16:34:09    Groovy script  if (repository_git_branch_0.equalsIgnoreCase("master")) return "publish" else return "preview"; evaluated to [publish]

While the bamboo variables are fine:

Beginning to execute external process for build '...'
..
bamboo_repository_git_branch=test/bamboo-trigger

Obivously the example is looking on the wrong variables and I have no clue how to access the regular Bamboo variables inside the Groovy scrioting

Comments (10)

  1. Julius Hutuleac repo owner

    according to the sample you provided 07-Dez-2015 16:34:09 repository_git_branch_0=master

    should evaluate to publish ... return "publish" else return "preview"; evaluated to [publish]

    not sure if I understand the question here ...

  2. Former user Account Deleted

    I'm referring to the example posted in the README.md.

    My report illustrates, that - The script is executed in a branch which becomes reflects in the Bamboo-Variable bamboo_repository_git_branch has the value test/bamboo-trigger (the actual branch name) - The reference example in the README.md does not work as intended, because it always looks into the variable repository_git_branch_0 which is always master even for branch plans .

    I'm wondering how to access & use the bamboo variable bamboo_repository_git_branch which contain the actual branch name. The non-working example in the README.md should be adjusted accordingly.

  3. Former user Account Deleted

    Thank you. I just updated & tried again.

    Unfortunately I do not see any additional Bamboo variables becoming visible. Maybe Bamboo sets the bamboo_repository_git_branch variable only after the checkout task and hence after the script evaluation occurs.

    Did the examples in the README work for you? I'm on Bamboo 5.9.4

    if (repository_git_branch_0.equalsIgnoreCase("develop")) return "develop";
    
  4. Julius Hutuleac repo owner

    You should see in your build log something like this:

    GroovyShell bindings: simple 18-Feb-2016 00:08:40 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; simple 18-Feb-2016 00:08:40 changeset_filter_pattern_regex_0= simple 18-Feb-2016 00:08:40 repository_common_quietPeriod_enabled_0=false simple 18-Feb-2016 00:08:40 repository_common_quietPeriod_period_0=10 simple 18-Feb-2016 00:08:40 repository_common_quietPeriod_maxRetries_0=5 simple 18-Feb-2016 00:08:40 repository_git_branch_0=develop simple 18-Feb-2016 00:08:40 repository_git_useShallowClones_0=false simple 18-Feb-2016 00:08:40 repository_git_useRemoteAgentCache_0=false simple 18-Feb-2016 00:08:40 repository_git_useSubmodules_0=false simple 18-Feb-2016 00:08:40 repository_git_commandTimeout_0=180 simple 18-Feb-2016 00:08:40 repository_git_verbose_logs_0=false simple 18-Feb-2016 00:08:40 repository_git_fetch_whole_repository_0=true simple 18-Feb-2016 00:08:40 repository_git_ssh_passphrase_0= simple 18-Feb-2016 00:08:40 repository_git_username_0= simple 18-Feb-2016 00:08:40 repository_git_authenticationType_0= simple 18-Feb-2016 00:08:40 Groovy Shell starting simple 18-Feb-2016 00:08:40 Groovy 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; evaluated to [.master.|.feature.]

  5. Julius Hutuleac repo owner

    the package for logging in case you would like to increase logging level is org.valens.

  6. Former user Account Deleted

    Thanks for your fast feedback.

    Hmmm.... Your output does not contain bamboo_repository_git_branch either.

    In my original issue you can see, that the script does actually see a repository_git_branch_0=master: I think this is the configured repository for the main plan. I only start to see the branch name for the branches created by Bamboos Automatic branch management after the checkout task in the environment variables.

    Do you use Automatic branch management?

  7. Log in to comment