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 Sign up to answer
Community showcase
Published Monday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

406 views 0 8
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