Quick start: Creating Promotion Workflows

Create a workflow template to use as pre- or post-action

Promotion Workflows quick start

This quick start will guide you through creating a Promotion Workflow in Codefresh.

Promotion Workflows are Argo Workflow Templates that automate tasks such as notifications, validations, and additional deployments before or after a promotion. They can be used in Promotion Flows to automate tasks before or after promotion.

For detailed information, see Configure Promotion Workflows.

This quick start includes examples of two Promotion Workflows:

  • Example 1: Promotion Workflow for Slack notifications
  • Example 2: Promotion Workflow to open a ServiceNow Change Request

Requirements

Example 1: Create Promotion Workflow to send Slack notifications

This example creates a Promotion Workflow that sends Slack notifications. The Workflow runs a container from Codefresh’s Argo Hub, which posts a message to Slack.

Creating a Promotion Workflow is as simple as creating an Argo Workflow Template which you can create directly from the UI.

For simplification, we are using a hard coded version of an existing template from our library.

Step-by-step
  1. In the Codefresh UI, from the sidebar, select Promotion Workflows, and click Add Promotion Workflow.
  2. Define the following:
    1. Name: A unique name for the Promotion Workflow, slack-notification for the quick start.
    2. Description: A meaningful description of the Workflow Template’s purpose. For example, A template to send a Slack notification.
    3. Resource Filename: The name of the manifest file that will be saved in resources/control-planes/promotion-workflows folder in your Shared Configuration Repository. By default, this is identical to the Name of the Workflow. Leave as-is for the quick-start.

Promotion workflow quick start: Create promotion workflow

Promotion workflow quick start: Create promotion workflow
  1. Click Add.
  2. Select Blank Skeleton File as the Workflow Template, and click Next.
  3. In the YAML editor on the right, replace the spec in line 13 with the following block:
    
    spec:
      serviceAccountName: promotion-template
      arguments:
        parameters:
          - name: APP_NAME
      entrypoint: slack-promotion
      templates:
        - name: slack-promotion
          container:
            name: main
            imagePullPolicy: Always
            image: quay.io/codefreshplugins/argo-hub-slack-post-to-channel:0.0.2-main
            command:
              - python
              - /slack/slack.py
            env:
              - name: SLACK_CHANNEL
                value: 'name@domain.com'
              - name: SLACK_MESSAGE
                value: 'Application `{{ workflow.parameters.APP_NAME }}` has been promoted' 
              - name: LOG_LEVEL
                value: 'info'
              - name: SLACK_TOKEN
                valueFrom:
                  secretKeyRef:
                    name: 'slack-token'
                    key: token          

where:

  • SLACK_MESSAGE is the message to display in the Slack notification. In the example, the message indicates that the application has been promoted.
  • SLACK_CHANNEL can either be the name of a Slack channel or the email of a user.
  • slack-token is the name of the secret holding your Slack Token, in the token key.
  1. Click Commit
  2. Optional. Feel free to add a Commit Message.
  3. Click Commit again.
    After a few minutes, the new Promotion Workflow is displayed in the Promotion Workflows list.

Promotion Workflow quick start: New Promotion Workflow in list

Promotion Workflow quick start: New Promotion Workflow in list
Example of Slack notification sent with this Promotion Workflow

This is an example of the Slack notification sent before promotion starts in an environment.

Promotion Workflow quick start: Slack notification example

Promotion Workflow quick start: Slack notification example

Example 2: Open a ServiceNow change request

This example creates a Promotion Workflow that opens a ServiceNow change request. The Promotion Workflow uses the existing ServiceNow Workflow Template from the Codefresh Argo Hub library.

Step 1: Add a Git Source for the Argo Hub library

To use the ServiceNow Workflow Template, first add a Git Source to your GitOps Runtime that points to the Argo Hub library.
See Add a Git Source.

  • Configure the Git Source using the settings shown in the example below.

Promotion Workflow quick start: Git Source settings for Argo Hub library

Promotion Workflow quick start: Git Source settings for Argo Hub library

Step 2: Create Promotion Workflow with ServiceNow change request

Create the Promotion Workflow with the ServiceNow change request.

  1. In the Codefresh UI, from the sidebar, select Promotion Workflows, and click Add Promotion Workflow.
  2. Define the following:
    1. Name: A unique name for the Promotion Workflow, sn-open-cr for the quick start.
    2. Description: A meaningful description of the Workflow Template’s purpose. For example, A template to open a ServiceNow Change Request before an application is promoted.
    3. Resource Filename: The name of the manifest file that will be saved in resources/control-planes/promotion-workflows folder in your Shared Configuration Repository. By default, this is identical to the Name of the Workflow. Leave as-is for the quick-start.

Promotion Workflow quick start: Example for ServiceNow

Promotion Workflow quick start: Example for ServiceNow
  1. Click Add.
  2. For the quick start, select Blank Skeleton File as the Workflow Template, and click Next.
  3. In the YAML editor on the right, replace the spec in line 15 with the following block:
  
   spec:
     serviceAccountName: promotion-template
     arguments:
       parameters:
         - name: APP_NAME   
       entrypoint: sn-open-cr
       templates:
       - name: sn-open-cr
         outputs:
           parameters:
           - name: CR_SYSID
             valueFrom:
               expression: "tasks['create-sn-cr'].outputs.parameters['CR_SYSID']"
         dag:
           tasks:
             - name: create-sn-cr
               templateRef:
                 name: argo-hub.servicenow.1.3.1
                 template: createcr
               arguments:
                 parameters:
                 - name: TOKEN
                   value: cf-api-key-aperture
                 - name: CF_RUNTIME
                   value: demo
                 - name: SN_INSTANCE
                   value: "https://xxxxxx.service-now.com/"
                 - name: SN_AUTH
                   value: "sn-auth"
                 - name: CR_DATA
                   value: >-
                     {"short_description": "{{ workflow.parameters.APP_NAME }} deployment",
                     "description": "Change for build {{workflow.uid}}.\nThis change was created by the Codefresh GitOps promotion flow",
                     "justification": "My app is awesome! Please deploy ASAP",
                     "cmdb_ci":"tomcat", "assignment_group":"a715cd759f2002002920bde8132e7018"
                     }

where:

  • TOKEN is the Codefresh API Key to allow Service Now to reach back to the Codefresh instance.
  • SN_AUTH is the secret holding credentials to connect to the ServiceNow instance (SN_INSTANCE)
  • CR_DATA is the JSON payload to be able to open a Change Request.
  1. Click Commit
  2. Optional. Feel free to add a Commit Message.
  3. Click Commit again.
    After a few minutes, the new Promotion Workflow is displayed in the Promotion Workflows list.

Using Promotion Workflows in Promotion Flows

After creating Promotion Workflows, you can add them to any Promotion Flow and automate key actions before or after promoting an environment.
These workflows help enforce policies, validate changes, and trigger external processes as part of the promotion lifecycle.

For example, you can configure the ServiceNow Promotion Workflow in example 2 as a Pre-Action Workflow in a Promotion Flow. The Workflow will then run before the changes are promoted to open a change request.

What’s next

Now that you have created all the entities required for GitOps-based promotions, you can trigger promotions to move application versions across environments.

We’ll start with a simple drag-and-drop promotion.

Quick start: Simple promotion with drag-and-drop