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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

97 views 1 0
Join discussion

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