Configure code source triggers for your pipeline, and specify triggering events and filtering conditions to control when pipeline runs start automatically.
Configure a code source trigger
After you enable the code source trigger and configure a webhook, Flow automatically runs the pipeline when code is committed to the specified repository and branch.
Alibaba Cloud DevOps Codeup
-
In Alibaba Cloud DevOps, go to your pipeline, click Edit Pipeline, and then click Edit Code Source.
-
Click Enable Code Source Trigger. Flow automatically adds the webhook URL to the corresponding Alibaba Cloud DevOps Codeup code repository.
After enabling the trigger, in the Triggering events section, select the desired event types, such as code commit, tag creation, merge request completed, and merge request created/updated. You can also enable branch or tag filtering and code path filtering. When you are finished, click Add.
After you enable the trigger, Flow automatically registers a webhook on the Webhooks settings page of your Alibaba Cloud DevOps Codeup code repository. The webhook covers push events, tag push events, and merge request events.
Other code sources
-
On the pipeline's edit page, click Edit Code Source. Enable Code Source Trigger, and copy the webhook URL.
In the Triggering events section, select code commit, and add the copied webhook URL to the webhook trigger settings of the corresponding code repository.
-
Add the copied webhook URL to the settings of the corresponding code repository. Alibaba Cloud DevOps supports code source triggers for GitLab, GitHub, Gitee, and General Git repositories. Configuration methods vary by repository type.
GitLab
Go to your GitLab code repository and navigate to . Paste the webhook URL copied from the pipeline into the URL field.
In the Trigger section, select Push events.
GitHub
Go to your GitHub code repository, navigate to , and click Add Webhook. Paste the webhook URL copied from the Flow pipeline into the Payload URL field. For Content Type, select application/json.
For the trigger, keep the default option: Just the push event..
Gitee
Go to your Gitee code repository and navigate to . Paste the webhook URL copied from the Flow pipeline into the URL field.
General Git
Using GitLab as an example, go to your GitLab code repository and navigate to . Paste the webhook URL copied from the pipeline into the URL field.
SVN
-
On the pipeline edit page, enable the code source trigger and copy the webhook URL.
For the triggering event, select code commit. The webhook URL is
http://flow-openapi.aliyun.com/scm. -
On the SVN server, navigate to the
hooksdirectory of your repository. Find the hook script templates. Each template corresponds to an event. To use a template, remove the.tmplsuffix.14:32 post-commit.tmpl 14:32 post-lock.tmpl 14:32 post-revprop-change.tmpl 14:32 post-unlock.tmpl 14:32 pre-commit.tmpl 14:32 pre-lock.tmpl 14:32 pre-revprop-change.tmpl 14:32 pre-unlock.tmpl 14:32 start-commit.tmpl -
Take
post-commitas an example. Thepost-commitfile is a shell script. SVN executes this script after a change is detected, such as a code commit, branch creation, or tag creation. The following example script shows how to trigger a Flow pipeline run upon a code commit:#!/bin/sh # The repository path and the commit revision number are passed to the script as arguments. REPOS="$1" REV="$2" # Use svnlook to find the directories changed in this commit. CHANGED_DIRS=$(svnlook dirs-changed -r "$REV" "$REPOS") # Get the first changed directory path, which is usually the top-level directory. FIRST_CHANGED_PATH=$(echo "$CHANGED_DIRS" | head -n 1) # Assume the branch structure follows the standard format (branches/branch-name). You can parse the branch name from the output. BRANCH_NAME=$(echo "$FIRST_CHANGED_PATH" | sed 's#.*/$branches/.*/$$\1#') # Construct a curl command to send a request to the webhook URL provided by the pipeline. # Replace the webhook URL with the one from your pipeline, and format the request data as shown in the example. curl --location --request POST 'http://flow-openapi.aliyun.com/scm/webhook/MwfQPTyf4nif2UdWBooR' \ --header 'Content-Type: application/json' \ --data-raw "{ \"ref\": \"refs/heads/$BRANCH_NAME\", \"repository\": { \"clone_url\": \"svn://8.142.XX.XXXcom/svn/repos/demo\" } }"
-
Triggering events
Use Triggering events to filter webhook events by code source. The following table lists supported events for each code source type.
|
Alibaba Cloud Code |
Alibaba Cloud DevOps Codeup |
General Git |
GitHub |
GitLab |
Coding |
Bitbucket |
Self-managed GitLab |
SVN |
|
|
Code commit |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✘ |
✓ |
✓ |
|
Tag creation |
✓ |
✓ |
✘ |
✘ |
✓ |
✘ |
✘ |
✓ |
✘ |
|
Merge request created/updated |
✘ |
✓ |
✘ |
✘ |
✘ |
✘ |
✘ |
✘ |
✘ |
|
Merge request completed |
✘ |
✓ |
✘ |
✘ |
✓ |
✘ |
✘ |
✓ |
✘ |
Code commit: Triggered when you push a local branch to a remote branch or edit files on your code platform's web interface (for example, pushing local master to origin/master). Flow matches the target branch against the filter conditions and, if they match, triggers the pipeline using that branch.
Tag creation: Triggered when you push a local tag to the server or create a tag on your code platform's web interface (for example, pushing local tag release/0.0.1 to the server). Flow matches the tag name against the filter conditions and, if they match, triggers the pipeline using that tag as the code version.
Merge request created/updated: Triggered when you create or update a merge request on your code platform's web interface. Only Alibaba Cloud DevOps Codeup supports this event. For example, if you create a merge request from the remote dev branch (source) to master (target), Flow matches the target branch against the filter conditions and, if they match, triggers the pipeline using the source branch.
Merge request completed: Similar to the merge request created/updated event, except Flow uses the target branch for the run.
Filtering conditions
Branch or tag filtering
Filter conditions support regular expressions. Enter a specific branch such as master or dev, or use Java-style regular expression syntax. For example:
-
To match multiple branches, such as
masteranddev, entermaster|dev. -
To match branches that start with
feature, enter^feature.*.
Code path filtering
Code path filtering lets you filter triggering events by the paths of modified files. This feature supports only Push events from Alibaba Cloud DevOps Codeup sources. Flow triggers the pipeline only when code changes match the filter rules. Filter conditions support regular expressions. For example, auth-srv/.* triggers the pipeline only when code in the auth-srv directory is updated.