Skip to content

Cloudbees CD/RO, send and receive parameters with bash / Ansible scripts

Sending a pipeline parameter to a bash or Ansible script is easy, but the reverse is less obvious.

In this article, we’ll look at how to return parameters from an Ansible script to a Cloudbees CD/RO job.

The easy way

You can easily transfer a parameter from the Cloudbees CD/RO procedure to an Ansible script. Simply pass the parameter or variable to the command to execute:

ansible-playbook playbooks/pipeline_action.yml -l $[ansibleHost] -e myAnsibleParam="${myCDParams}"

Types of arguments

Many kinds of data can be used to transfer values to Ansible script:

  • Input Parameter, from pipeline or procedure form. Exemple: $[myParameter]
  • Properties, from any object in Cloudbees CD/RO. Exemple: $[/projects/my_project_name/my_property]
  • Variable, define on procedure runtime. Exemple: ${my_varaibles}

Getting data, the hard way

Sending data is easy, but receiving data from a script to use it into a pipeline is more complicated.

Questions about your own setup? A dbi services consultant can look at your case.

Talk to an expert (opens in a new tab)

To obtain data from a script, you need to run a script that creates a property for the job. After that, the property can be used in the procedure run.

Running a script to get data

Simply run a script, such as:

ansible-playbook playbooks/get_values.yml 

Parameter transfer takes place inside the script using the Cloudbees CD/RO command ectool:

- name: Define environment
  command: "ectool setProperty /myJob/environmentCreated {{ success_state }}"

This task defines an “environmentCreated” property in the job scope with as value for the ansible variable success_state.

You can create as many properties as you need.

Using the property

Like all properties, it can be accessed using $[…]
Example:

if [[ "$[/myJob/environmentCreated]" == "success" ]]; then
   ...

Conclusion

Retrieving values from a script in Cloudbees pipelines is perfectly possible using ectool, however, scripts need to be adapted to define properties that can be used in procedures.

To learn more about properties, see the Cloudbees CD/RO documentation

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Nicolas Meunier

Nicolas Meunier

Nicolas Meunier specializes in cloud solutions and has more than 20 years of experience in IT web technologies and development, including CI/CD, Kubernetes, Docker, Jenkins-X, and Azure DevOps. Prior to dbi services, he developed and maintained a CI/CD pipeline at CEGID in Paris and worked as Lead Developer at KPMG. He holds a superior technical diploma in IT development. His background covers software and cloud platform architecture.View Author posts

21 posts since November 2022

Most read in Ansible

The Ansible posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *