Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to update global variables through a plugin?

vamsi k August 21, 2017

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

0 votes
Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 23, 2017

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);
vamsi k August 23, 2017

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?

Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 25, 2017

add it 

@ComponentImport
@Autowired
private VariableDefinitionManager variableDefinitionManager

or in atlassian-plugin.xml

<component-import key="variableDefinitionManager" interface="com.atlassian.bamboo.variable.VariableDefinitionManager" />
vamsi k August 26, 2017

It is not reporing variableDefinitionManger bean not found error.

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

Alexey Chystoprudov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 28, 2017
<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
TAGS
AUG Leaders

Atlassian Community Events