How can I change the Micro Focus ALM password in my jobs programmatically?

Article ID:360028553272
2 minute readKnowledge base

Issue

  • The Micro Focus Application Automation Tools does not allow you to use global credentials, thus, you need to enter them in every single job using it. Changing the password programmatically could cover the use case where the server password changes.

Resolution

One potential approach is to run the script shown below from the Script Console in your controller instance:

Manage Jenkins->Script Console

Important Notice: This script is intended to perform changes in your jobs configuration, thus it is highly recommended to be sure that we have a working backup for the jobs that we are going to update.

import com.microfocus.application.automation.tools.run.RunFromAlmBuilder
def projects= hudson.model.Hudson.instance
def new_password="New value to set"
def DRY_run=true
//Set jobName="" to ignore jobName filtering
def jobName="test_job"

projects.getAllItems(Job).each{

  //We can filter by job name. Comment the corresponding lines to apply the changes to every job
  if (it.getFullName()==jobName || jobName==""){
  //We iterate over different jobs and select the ones using the corresponding builder
   it.builders.each{ builder -> builder instanceof com.microfocus.application.automation.tools.run.RunFromAlmBuilder

 /*We need to create a new instance class but recovering every value from the existing class except for the password which we
  pass as parameter
*/
     if(!DRY_run){
      RunFromAlmBuilder new_builder = new  RunFromAlmBuilder( builder.almServerName,
             builder.almUserName,
            "${new_password}",
            builder.almDomain,
            builder.almProject,
            builder.almTestSets,builder.almRunResultsMode,
            builder.almTimeout,
            builder.almRunMode,
            builder.almRunHost, builder.isFilterTestsEnabled,builder.filterTestsModel)

     //We remove the existing values
     it.buildersList.remove(builder)
     //We add the new ones
     it.buildersList.add(new_builder)
     //We save the job
     it.save()
     }
     println "The job "+ it.getFullName() + (DRY_run?" was not changed as this was a test run":" was updated successfully!").toString()
   }

  }

}

You can configure the script changing the values for the variables below:

  • Set the DRY_run variable to false when you want the script to change the password.

  • If you set JobName variable to "" the script will go over every job using ALM.

  • If you want to change only one job, please provide the full project name in JobName variable.

Another potential approach is to take advantage of your Operations Center, and create a cluster operation to run the above described Groovy script in different controllers (Client controllers or Managed controllers). But essentially, the outcome would be the same.