Working with Properties Stored in a Procedure

2 minute read

This tutorial shows common ways to read and write properties on a procedure. For this tutorial, familiarity with creating procedures and steps is assumed. See Related Information if you would like to review these topics.

To view an example procedure for this tutorial , go to the automation platform UI > Projects > EC-Tutorials- <version> , and click the procedure name.

An explanation of what you see—this procedure implements the following functionality:

  • This procedure implements five steps. Each step name is a description of its action.

  • Click on a step name to go to the corresponding Edit Step page to see how the step was created. This page also contains text in the Description text box to describe what you see in the Action column on the Procedure Details page. The full text of what appears in the Action column is provided in the Command text box.

  • In the Custom Procedure Properties table, notice two properties were created: property1 and property2

  • There are numerous ways to work with stored properties. Each of the steps described below illustrates a different method.

  • Read data from property1 using the property substitution notation (syntax): The property value is read in this step using the property substitution reference $[/myProcedure/property1].

  • Read data from property1 using inline JavaScript: The property name property1 is read from the procedure level using this JavaScript notation: $[/javascript myProcedure.property1].

  • Perform a calculation using data from property 2 and inline JavaScript: In this example, the value of property2 is multiplied by 5 using this JavaScript notation: $[/javascript myProcedure.property2 * 5].

  • Read data from a property1 using the CloudBees CD Perl API: Perl code is used to call the CloudBees CD API to retrieve the value of property1. The getProperty API returns an object so the property value must be retrieved after the getProperty call, using the findnodes method for the returned object.

  • #read the property my $property1node = $ec→getProperty(“/myProcedure/property1”); #retrieve the property value from the object returned to $property1node my $property1 = $property1node→findnodes(“//value”)→string_value();

  • Read data from property1 using ectool: ectool code is used to retrieve the value of property1:

ectool getProperty "/projects/$[/myProject/projectName]/procedures/Working with properties stored in a procedure/property1"

Click Run to run this sample procedure and see the results on the Job Details page. On the Job Details page, click the icon in the Log column to see the value read from the property.

Implementation

If you need to retrieve properties stored in a procedure, adapt any one of these step concepts to your procedures. You can reuse the text supplied in the Command(s) box (from any Edit Step page in this tutorial), changing names and other values to those more meaningful to your project/procedure.

Any changes you make within this tutorial will not be saved when you upgrade CloudBees CD.