DMS enables you to use third-party DevOps pipelines, including Alibaba Cloud DevOps Flow and pipelines configured in Jenkins, to trigger automated continuous integration and continuous delivery/deployment (CI/CD) for Airflow tasks. This topic describes how to build Alibaba Cloud DevOps and Jenkins pipelines.
Background information
Flow is an enterprise-level, automated continuous integration and continuous delivery tool that helps enterprises automate the entire process from code development to deployment in a production environment. This tool can improve development efficiency, accelerate delivery speed, and reduce error rates.
Prerequisites
You have set up an Airflow environment.
Configure an Alibaba Cloud DevOps pipeline
Step 1: Create a pipeline
Log on to the Flow console.
On the My Pipelines page, click Create Pipeline in the upper-right corner. For more information, see Create your first pipeline.
On the Visualization Orchestration tab, click Empty Template in the navigation pane on the left, select **Empty Template**, and then click Create.
After the pipeline is created, you are redirected to the pipeline configuration page.
Step 2: Configure a trigger source to trigger pipeline runs
A pipeline can be triggered by sources such as webhooks or GitHub repositories.
Manually configure a webhook
On the pipeline Trigger Settings page, turn on the Webhook Trigger switch.
Copy the generic webhook URL and click Save Only in the upper-right corner.
Open your GitHub repository, select Settings in the top menu bar, and then click Webhooks in the navigation pane on the left.
Click Add webhook.
Paste the copied generic webhook URL into the Payload URL field, select a Trigger Type, and then click Add webhook. You can use the default values for the other parameters.
Associate a GitHub repository
Go to the Flow Flow Configuration page and click Add Pipeline Source.
On the Code Source page, select GitHub and then click Add.
For the initial configuration, you must add a service connection to grant authorization to GitHub. Then, you can add a Git repository.
After you add the GitHub repository, select the code repository and the Default Branch, and then select Enable Code Source Trigger.
Copy the webhook URL.
Open the destination GitHub repository, select Settings in the top menu bar, and then click Webhooks in the navigation pane on the left.
Click Add webhook.
Paste the copied generic webhook URL into the Payload URL field, select a Trigger Type, and then click Add. You can use the default values for the other parameters.
Associate a GitLab repository
On the Flow Flow Configuration page, click Add Pipeline Source.
On the Code Source page, select Self-managed GitLab.
Specify the Code Repository and Default Branch parameters. For Credential Type, select Organization Public Key. The organization public key is generated in your GitLab account settings. Select Enable Code Source Trigger. You can use the default values for the other parameters.
After you enable the code source trigger, copy the webhook URL.
Open the destination GitLab repository, go to the webhook settings page, paste the webhook URL into the Webhook URL field, and select a trigger source as needed.
Click Add webhook.
Step 3: Configure global environment variables
Global environment variables can be used in all task nodes of the pipeline.
On the Flow Edit page, click Variables And Cache.
In the String Variable section, click New Variable.
Add the following variables and their default values, and then click Add.
The following table describes the variables.
Variable Name
Required
Description
ALIBABA_CLOUD_ACCESS_KEY_ID
Yes
The AccessKey of your Alibaba Cloud account
ALIBABA_CLOUD_ACCESS_KEY_SECRET
Yes
The AccessKey secret of your Alibaba Cloud account
DMS_CICD_PROJECT_ID
Yes
DMS_CICD_BRANCH_NAME
Yes
Deployment branch
DMS_CICD_WORKSPACE_ID
Yes
Step 4: Configure the task flow
Delete the empty task node in Stage 1 of the flow.
On the flow configuration page, select and delete the Empty Task node.
Create a new node.
In the new stage, click New Task and find the Execute Command node.
Edit the task execution node.
Go to the node configuration page to configure the parameters for the task node. You only need to configure the following parameters. You can use the default values for other parameters.
Parameter
Description
Task Name
Each task node corresponds to a deployment environment. We recommend that the name of each task node reflect the environment context of the node. For example, dev environment.
Build Cluster
Keep the default selection (Singapore Build Cluster).
Download Pipeline
Select Do Not Download Pipeline Sources.
Task Step
Expand the text box for executing commands and enter the following script.
wget 'https://dms-cicd-tool-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/dms_cicd_tool' chmod +x ./dms_cicd_tool ./dms_cicd_toolConfigure environment variables for the task node.
In the Environment Variables section of the node configuration page, select .
Variable Name
Meaning
Required
Example
DMS_CICD_DEPLOY_COMMON
Remarks for the deployment task
No
DEV environment deployment test
DMS_CICD_DEPLOY_PARAM
Additional parameters for the deployment task
No
{"param1":"value1"}
NoteThis is a local variable, which means it is effective only in this task node.
You can repeat substeps 2, 3, and 4 to create and configure multiple task nodes.
In the upper-right corner of the page, click Save and Run.
Step 5: Run the pipeline and view run records
After you configure the trigger source, the task is automatically triggered by the webhook. You can also run the task manually.
Run the task manually
In the upper-right corner of the pipeline configuration page, click Save and Run.
View run records
On the run history page, click View to see the details of all pipeline runs, including the run duration and logs of task nodes. Click Log in the task node section to view information, such as the run result and the cause of a deployment failure for the destination node.
NoteA success flag for a task node run:
XXX successappears in the **Execute Command** section.A failure flag for a task node run:
XXX failedappears in the **Execute Command** section.
Configure a Jenkins pipeline
Step 1: Configure the pipeline script
Log on to Jenkins.
If you have not downloaded Jenkins, go to the official Jenkins website to download and install it.
In the navigation pane on the left, click New Item.
Enter a task name and click the Pipeline tab.
Modify the information in the following script, such as `ALIBABA_CLOUD_ACCESS_KEY_ID`, `ALIBABA_CLOUD_ACCESS_KEY_SECRET`, and `Webhook Token`, as needed. Paste the content into the text box and then click Save.
pipeline { agent any environment { DMS_CICD_PROJECT_ID=xxxx DMS_CICD_BRANCH_NAME="master" ALIBABA_CLOUD_ACCESS_KEY_ID="xxxxx" ALIBABA_CLOUD_ACCESS_KEY_SECRET="xxxxx" DMS_CICD_WORKSPACE_ID=xxxx } stages { stage('Build') { steps { sh 'wget "https://dms-cicd-tool-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/dms_cicd_tool"' sh 'chmod +x ./dms_cicd_tool' echo 'Build step finished' } } stage('Deploy') { steps { sh './dms_cicd_tool' echo 'Deploy finished' } } } }
Step 2: Configure a trigger
Subsequent Airflow tasks are automatically triggered. You can also manually run tasks in the Airflow workspace.
Make sure that the Generic Webhook Trigger plugin is installed in Jenkins.
Go to the pipeline project, click Manage Jenkins > Manage Plugins, select Generic Webhook Trigger, and specify the GitLab Token.
You can obtain the GitLab token from the procedure described in the Associate a GitLab repository section.
Configure a GitHub trigger.
In the top menu bar of the destination GitHub repository, click Settings, and then click Webhooks in the navigation pane on the left.
Click Add webhook.
Paste the generic webhook URL of the pipeline into the Payload URL field, enter the token in the Secret field, and select a Trigger Type.
Click Add webhook.
Configure a GitLab trigger.
Open the destination GitLab repository and choose .
Paste the generic webhook URL of the pipeline into the Payload URL field, enter the token in the Secret field, and select a Trigger Source.
Click Add Webhook.
Other operations
View the REPO project ID
Go to the workspace and click the
icon in the left-side menu bar. In the REPOS section, click the
icon next to the destination repository to view the REPO Project ID.