vRealize Code Stream – Pipeline As A Service

logo

Introduction:

vRealize Code Stream pipelines can be executed in couple of different ways depending on the customer scenario.
One option is to use the execute button in the pipelines screen, this will execute the proper pipeline.
Another option is using the rest api to execute a specific pipeline.
There are some sample scripts and code in vRCS documentation that explain how to interact with vRCS Rest API.
In this post i will show how to use vRealize Orchestrator HTTP-REST plug-in to execute a vRCS pipeline.
This is very useful in a use case where we need outbound developers or DevOps engineers to trigger pipelines based on specific roles and permission.
It can also help where we are using vRO API as a central API for cloud and SDDC and need to trigger multiple actions in multiple products (vRA, vRCS) from external apps.

blog1

workflowStep1 -vRealize Orchestrator – Add A REST host

In the first step we need to configure vRCS as our REST host:

  1. Open your vRO client and go to Library> HTTP-REST> Configuration.
  2. Run the Add a REST host workflow and fill up your vRCS host’s details as follows:
  1. add_rest_host-1
  2. add_rest_host-2
  3. add_rest_host-3
  4. add_rest_host-4
  1. in the last screen enter your tenant username and password to complete the process.

workflowStep2vRealize Orchestrator – Add A REST operations

Now we need to add some rest activities that will define our rest calls to vRealize Code Stream API.

REST Operation 1 – get vRealize Code Stream authentication token.

In this call we will authenticate against Code Stream and get the Authentication token, it will be used later in other API calls.
*The token is good for 24H

  1. Open your vRO client and go to Library> HTTP-REST> Configuration.
  2. Run the Add a REST operation workflow and fill up the details as follows:

URL: /identity/API/tokens

  1. add_rest_operation-get token

REST Operation 2 – get vRealize Code Stream pipeline list.

In this call, we will use Code Stream API to get the pipeline list.
We will use this list later to choose the right pipeline to execute.

  1. Open your vRO client and go to Library> HTTP-REST> Configuration.
  2. Run the Add a REST operation workflow and fill up the details as follows:

URL: /release-management-service/API/release-pipelines

  1.  add_rest_operation-get-pipline list

REST Operation 3 – get vRealize Code Stream pipeline information.

In this call, we will use Code Stream API to get a particular pipeline information.
We will need to supply the pipeline name.
We will use this later to get the pipeline running status.

The information that comes out from this call is in JSON format.

  1. Open your vRO client and go to Library> HTTP-REST> Configuration.
  2. run the Add a REST operation workflow and fill up the details as follows:

URL: /release-management-service/api/release-pipelines?name={pipeline_name} 

  1. add_rest_operation-get pipeline info

REST Operation 4 – execute vRealize Code Stream pipeline.

In this call, we will use Code Stream API to run a pipeline.
We will need to supply the pipeline ID.

The information that comes out from this call is in JSON format.

  1. Open your vRO client and go to Library> HTTP-REST> Configuration.
  2. run the Add a REST operation workflow and fill up the details as follows:

URL: /release-management-service/api/release-pipelines/{pipeline_id}/executions 

  1. add_rest_operation-execute pipeline

workflowStep3 – vRealize Orchestrator – Build vRO
workflow to run a pipeline.

You can just create a vRO workflow from each REST operation by running the “Generate a new workflow from rest process” workflow.
This will create a simple workflow that will let you input the right parameters and execute the particular RSET call.

* be sure to add the following line to your script to make sure you first authenticated to Code Stream before you run the REST operation (where the token is a string variable you need to pass with the token obtained in step 2 operation1):

request.setHeader(“Authorization”,”Bearer”+” “+token);

to make life easier I have created 3 vRO action to represent the REST operations and a sample workflow to run them.
here is the instruction on how to use it:

workflowImport the vRO Code Stream package

  1. Download my vRO Code Stream Package: com.vmware.codestream.package
  2. Go to vRO main screen and press the “import package” button.
  3. Choose the place to add the package.
  4. Find the “Run Pipeline” workflow.
  5. It will look like this:run_pipeline_schema
  6. Edit the workflow and go to the General TAB to see the workflow attributes.
  7. Edit the following attributes:
    1. username – your Code Stream username (user@domain).
    2. password – your Code Stream password.
    3. tenant – your Code Stream tenant.
    4. tokenRest – link to the get token REST operation.
    5. listREst – link to the get pipeline list REST service.
    6. getPipelineDetails – link to the get pipelines REST service.
    7. executePipeline – link to the Execute Pipeline REST operation.
    8. Save the “Run Pipeline” workflow.
  8. Run the pipeline.
  9. you will get a screen like this:
    run pipeline
  10. Choose the pipeline you want to run.
    run pipeline2
  11. if you want to supply pipeline parameters enter them in JSON format in the content section.
  12. Press Submit to run the pipeline.
  13. The vCO workflow will execute the pipeline and wait until it’s completed.

*Pleas note I haven’t implemented any exception codes in the workflow so if you need to run this in production some more work will be required…

 vRA Step4 – Create a vRealize Automation Advance Service to run pipelines

  1. Open vRA and go to the Advanced Services TAB.
  2. Press Add and select your workflow from the list.
  3. Press next until the wizard finish.
  4. Go to  Administration TAB and select Catalog Items.
  5. Press the Code Stream workflow you just added.
  6. Check a particular Service to insert the workflows too.
  7. Add a Code Stream logo icon to the service: vrcs_logo
  8. Press update.
    *You have to set the right entitlements to see the Code Stream workflow in your catalog, refer to vRA documentation if you don’t know how to do that…
  9. Go to vRA catalog.
  10. You will see a new catalog item like this:
    catalog_iteam-run pipeline
  1. Request the catalog item.
  2. You will get a screen like this:
    catalog_iteam-new request
  3. Press the checklist near the pipeline_name, and you will get the list of pipelines from your Code Stream server.
    catalog_iteam-new request list
  4. Choose your workflow to run, if needed add some parameters in the content section and press submit. (parameters need to be in JSON format{“parameter_name”:”parameter_value”})
  5. A new request will be initiated in vRA, the request will stay open until the Code Stream pipeline is completed.
    request


This is Just an example on how to use the vRO HTTP-REST to execute Code Stream pipelines.
To get the full list of Code Stream API functions and capabilities go to:
https://<vRCS-SERVER-FQDN>/release-management-service/API/docs/