How to update global variables through a plugin?

I'm trying to update a global variable that contains authentication token. This token must be updated every 90 days. what is the atlassian code to do so?

Found from online there is com.atlassian.bamboo.configuration.variable.ConfigureGlobalVariables. how to initialize it and add bamboo plan to run periodically and update authentication token.

1 answer

For reference you can check com.atlassian.bamboo.plugins.rest.admin.globalvariable.RestGlobalVariableServiceImpl#updateGlobalVariable

final VariableDefinition variableDefinition = variableDefinitionManager.findVariableDefinition(variableId);
/*or*/

variableDefinition = variableDefinitionManager.getGlobalVariables().stream().filter(byName).findFirst().get();

String preValue = variableDefinition.getValue();
variableDefinition.setValue("new value");
variableConfigurationService.updateVariableDefinition(variableDefinition, preValue);

How do we initialize  variableDefinitionManager?

 If I have a global variable 

        key:fortify.auth.token

        value: xxxxxx-xxxx-xxxx-xxxx-xxxxxx

Will String preValue=variableDefinition.getValue(); sets preValue to xxxxxx-xxxx-xxxx-xxxx-xxxxxx?

Will variableDefinition.setValue("yyyyyy-yyyy-yyyy-yyyy-yyyyyy"); save global variable fortify.auth.token to yyyyy-yyyy-yyyy-yyyyyy perimenently {All the plans uses new value instead of previous value}?

_______________________________________________

can you provide me sample code that updates global variable in above case using 

  • com.atlassian.bamboo.plugins.rest.admin.globalvariable.RestGlobalVariableServiceImpl #
  • updateGlobalVariable(javax.ws.rs.core.UriInfo uriInfo, long variableId,RestGlobalVariable restGlobalVariable)

How to initialize uriInfo to a link http://xxxxxxx:zzzzz/kfdjg/dfd/

and restGlobalVariable?

add it 

@ComponentImport
@Autowired
private VariableDefinitionManager variableDefinitionManager

or in atlassian-plugin.xml

<component-import key="variableDefinitionManager" interface="com.atlassian.bamboo.variable.VariableDefinitionManager" />

It is not reporing variableDefinitionManger bean not found error.

Can you say me jar to be includedin pom.xml?

<dependencies>
...
<
dependency>
<groupId>com.atlassian.bamboo</groupId>
<artifactId>atlassian-bamboo-api</artifactId>
<scope>provided</scope>
</dependency>
...
</dependencies>

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,068 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot