流水线源 sources

流水线源(sources)是数据处理和集成系统中的一个关键组成部分,负责从不同的数据源中捕获和传输数据。

背景信息

流水线源sources:Flow 目前支持配置代码源、JenkinsFlow流水线源,并且支持配置多个源。

  • 代码源:支持配置 Codeup、GitHub、GitLab、Gitee、svn等常见代码源。

  • 制品源:支持配置云效packages源、阿里云ACR镜像源(企业版)。

  • Jenkins源:支持配置外部 Jenkins 服务触发流水线运行。

  • Flow流水线源:支持配置其他Flow流水线作为源,流水线之间相互触发运行。

示例

单流水线源

以下为一个最简单的流水线源配置示例:

sources:
  my_repo:
    type: codeup
    name: 代码源名称
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    triggerEvents:
      - push
      - tagPush
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

多流水线源

以下为多流水线源配置示例:

sources:
  repo1:
    type: codeup
    name: 代码源名称
    endpoint: https://codeup.aliyun.com/abc/repo1.git
    branch: master
    triggerEvents:
      - push
      - tagPush
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>
  repo2:
    type: codeup
    name: 代码源名称
    endpoint: https://codeup.aliyun.com/abc/repo2.git
    branch: master
    triggerEvents:
      - push
      - tagPush
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>
  repo3:
    type: svn
    name: 代码源名称
    endpoint: "<your-svn-url, eg: svn://svn.example.com/repo> or https://svn.example.com/repo"
    branch: trunk
    triggerEvents: push
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>
defaultWorkspace: repo1

packages 源示例

以下为云效packages通用制品作为流水线源的配置示例:

sources:
  my_packages:
    type: packages
    repoType: generic                                            # 仓库类型,目前只支持通用制品仓库generic
    repo: "<your-repo-id>, eg: flow_generic_repo"                # 仓库id,可以在packages.aliyun.com页面从仓库基本信息获取仓库id
    artifact: "<your-artifact-name>, eg: Artifacts_1418394"      # 制品名称
    version: "<your-artifact-version>, eg: 2024-03-28-11-53-39"  # 制品版本,如果填latest,则表示使用最新版本
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

ACR 源示例

以下为 阿里云ACR企业版镜像作为流水线源的配置示例:

sources:
  my_acr:
    type: acr
    region: cn-hangzhou
    instance: "<your-acr-ee-instance>, eg: yunxiao"  # ACR实例名称
    namespace: default                               # 命名空间
    imageRepo: "<your-docker-registry>, eg: test"    # 镜像仓库名称
    imageTag: v1.0                                   # 镜像版本
    versionFilter: .*                                # 镜像版本的过滤规则,请填写正则表达式
    triggerEvents:
      - pushCompleted
      - scanCompleted
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

Jenkins 源示例

以下为 Jenkins 任务作为流水线源的配置示例:

sources:
  my_jenkins:
    type: jenkins
    name: Jenkins 源名称
    jenkinsJob: job/job-test
    build: lastSuccessfulBuild
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

Flow 流水线源示例

以下为 Flow 流水线作为流水线源的配置示例:

sources:
  ci_pipeline:
    type: flowPipeline
    name: Flow 流水线源名称
    flowPipeline: <your-flow-pipeline-id>  # 形如:rfkkfe6tj1mcaqtz
    build: lastSuccessfulBuild
    triggerEvents: buildSuccess

详细说明

sources

流水线源,支持配置多个流水线源信息,包括源类型、源地址、默认分支等。

defaultWorkspace

当流水线配置了多个代码源时,必填。默认工作区,后续流水线任务若未指明工作空间,自动进入默认工作区执行任务。填写具体 <source_id>,如:

sources:
  repo1:
    ......
  repo2:
    ......
defaultWorkspace: repo1

sources.<source_id>

必填。流水线源 id,唯一标识流水线源。流水线运行时,会将源文件下载至 <source_id> 文件目录下(ACR镜像源不会下载),即/root/workspace/<source_id>。 source_id 只能包含字母、数字和 _ ,且必须以字母开头,长度限制 30 个字符。

sources.<source_id>.type

必填。流水线源类型,Flow目前支持Codeup、gitHub、gitLab、svn、Jenkins、packages、acr等多种流水线源类型。

流水线源类型

YAML 标识

备注

示例代码源

gitSample

  • 支持多种语言类型的示例代码仓库,如Java、Go、Python、C++、NodeJS、PHP、.NET Core。

  • 不支持触发事件。

云效 Codeup

codeup

  • 支持触发事件:代码提交、Tag 创建、合并请求完成后、合并请求新建/更新

  • 支持根据分支过滤

  • 支持根据代码路径过滤

码云

gitee

  • 支持触发事件:代码提交

  • 支持根据分支过滤

通用 Git

git

  • 支持触发事件:代码提交

  • 支持根据分支过滤

Github

github

  • 支持触发事件:代码提交

  • 支持根据分支过滤

Gitlab

gitlab

  • 支持触发事件:代码提交、Tag 创建、合并请求完成后

  • 支持根据分支过滤

自建 Gitlab

customGitlab

  • 支持触发事件:代码提交、Tag 创建、合并请求完成后

  • 支持根据分支过滤

自建Gitlab(API V4及以上版本)

gitlabAPI

  • 支持触发事件:代码提交、Tag 创建、合并请求完成后

  • 支持根据分支过滤

Bitbucket

bitbucket

  • 支持触发事件:代码提交

  • 支持根据分支过滤

svn

svn

  • 支持触发事件:代码提交

  • 支持根据分支名过滤

Jenkins

jenkins

  • 支持配置外部 Jenkins 服务触发流水线运行

Flow 流水线

flowPipeline

  • 支持配置其他Flow流水线作为源,流水线之间相互触发运行

  • 支持触发事件:流水线运行成功、失败、取消

Packages 通用制品

packages

  • 支持配置云效packages通用制品作为源

  • 不支持触发事件

阿里云 ACR 企业版镜像仓库

acr

  • 支持配置阿里云ACR企业版仓库镜像作为源

  • 支持触发事件:镜像推送完成、镜像扫描完成

  • 支持根据版本号过滤

sources.<source_id>.name

选填。长度限制 30 个字符。流水线源的展示名称。

sources.<source_id>.endpoint

当流水线源为代码源时,必填。代码源地址,支持填写 SSH 和 HTTPS 地址。如:https://codeup.aliyun.com/abc/Codeup-Demo.git。

示例代码库由云效提供,代码源地址如下:
Java:https://atomgit.com/flow-example/spring-boot.git
Go:https://atomgit.com/flow-example/go-gonic.git
Python:https://atomgit.com/flow-example/python-tornado.git
C++:https://atomgit.com/flow-example/gcc-helloworld.git
NodeJS:https://atomgit.com/flow-example/node-expressjs.git
PHP:https://atomgit.com/flow-example/php-laravel-blog.git
.Net Core:https://atomgit.com/flow-example/dotnet-core-sample.git

sources.<source_id>.branch

非必填,当流水线源为代码源时,默认为 master。 代码源默认分支,当流水线被定时触发或被外部系统触发时,默认使用的运行分支。 填写分支名,如:

sources:
  my_repo:
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master

示例代码源仅支持 master 分支。

sources.<source_id>.branchesFilter

非必填,指定流水线运行分支的过滤规则,请填写正则表达式。仅满足过滤规则的分支或标签可以触发流水线运行,在手工触发、代码源触发、定时触发、Webhook 触发各场景均生效。

sources:
  my_repo:
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: release
    branchesFilter: release_*     # 仅可运行以 release_ 开头的分支

sources.<source_id>.submodule

非必填,默认为 false。当流水线源为代码源时,是否同时克隆子模块。填写truefalse,如:

sources:
  my_repo:
  	type: codeup
  	endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    submodule: true

sources.<source_id>.cloneDepth

非必填,默认克隆所有版本。仅支持填写大于等于 0 的数字整数。当流水线源为代码源时,克隆深度值代表克隆最近 commit 的版本数,自定义克隆深度可加速工作区准备效率,0 表示克隆所有版本。 如:

sources:
  my_repo:
    type: codeup
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    cloneDepth: 10

sources.<source_id>.triggerSecret

仅支持Github。

GithubWebhook配置中添加了Secret后,需要在流水线配置中也添加相同的值,以便在处理Webhook时,进行签名校验。

支持直接填写,或者使用变量,比如

  triggerSecret: ${SECRET}

或者

  triggerSecret: theSecret

sources.<source_id>.triggerEvents

非必填,默认无法通过流水线源事件触发。当发生对应配置的事件后,流水线触发运行。

触发事件

YAML 标识

备注

代码推送

push

Tag 创建

tagPush

仅支持部分代码源

合并请求完成后

mergeRequestMerged

仅支持部分代码源

合并请求新建/更新

mergeRequestOpenedOrUpdate

仅支持部分代码源

流水线运行成功

buildSuccess

仅支持 Flow 流水线源

流水线运行失败

buildFail

仅支持 Flow 流水线源

流水线运行取消

buildCancel

仅支持 Flow 流水线源

ACR镜像推送完成

pushCompleted

仅支持 ACR 流水线源

ACR镜像扫描完成

scanCompleted

仅支持 ACR 流水线源

如:

sources:
  my_repo:
    type: codeup
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    triggerEvents: 
      - push
      - tagPush

sources.<source_id>.branchFilter(Deprecated)

说明

本关键字已处于 Deprecated 状态,请使用上述 sources.<source_id>.branchesFilter 关键字替代。

非必填,默认不对分支进行过滤。当流水线源为代码源且开启代码源提交触发时,可以设置分支过滤条件,满足过滤条件才会触发流水线运行。填写分支名,支持正则表达公式,如:

sources:
  my_repo:
    type: codeup
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    triggerEvents: push
    branchFilter: ^feature.*  # 本关键字已处于 Deprecated 状态,请使用 branchesFilter 替代

sources.<source_id>.pathFilter

非必填,默认不对代码路径进行过滤。当流水线源为代码源且开启代码源提交触发时可以设置代码路径过滤条件,指定代码路径下的代码文件才会触发流水线运行。填写代码路径地址,支持正则表达式,如:

sources:
  my_repo:
    type: codeup
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    triggerEvents: push
    pathFilter: ^file_path.*

sources.<source_id>.branchMode

非必填,默认不打开分支模式。当流水线拥有多个流水线源时,仅允许一个代码源打开分支模式。

sources.<source_id>.branchMode.branchModelBranchFilter

非必填,分支模式参数,若代码源打开了分支模式,且配置了branchModelBranchFilter,只允许满足 branchModelBranchFilter 正则条件的分支运行。

sources.<source_id>.branchMode.keepIntegrationAreaBranch

非必填,分支模式参数,值为boolean,默认值为false,值为true时,合并分支后不清空集成区。

sources.<source_id>.branchMode.baseBranch

分支模式参数,若代码源打开了分支模式,则必须填写baseBranchbaseBranch为分支模式中拉取发布分支的基础分支,如:

sources:
  my_repo:
    type: codeup
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    branchMode:
      baseBranch: master
      keepIntegrationAreaBranch: false
      branchModelBranchFilter: feature/.*

sources.<source_id>.certificate

当 sources.<source_id>.type 为 gitSample、git 或 flowPipeline 时,非必填;其他场景必填。设置克隆代码源,或调用外部 Jenkins 服务的授权信息。使用服务连接,则 type 为 serviceConnection,并填写 服务连接 ID 信息(服务连接 ID 请前往 企业设置服务连接管理 获取),如:

sources:
  my_repo:
    type: codeup
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

部分代码源(如通用 Git、自建 GitLab等)支持通过企业公钥克隆代码,则可设置使用企业公钥,type 为 sshKey,如:

sources:
  my_repo:
    type: customGit
    endpoint: https://codeup.aliyun.com/abc/Codeup-Demo.git
    branch: master
    certificate:
      type: sshKey

sources.<source_id>.jenkinsJob

当流水线源为 Jenkins 源时,必填。 填写 Jenkins 的 Job 信息,如:

sources:
  my_jenkins:
    type: jenkins
    jenkinsJob: job-test
    ......

sources.<source_id>.flowPipeline

当流水线源为 Flow 流水线时,必填。填写 Flow 的流水线 ID(由16位随机字母组成),如:

sources:
  my_ci_pipeline:
    type: flowPipeline
    flowPipeline: atf******cmaofmk
    ......

sources.<source_id>.build

当流水线源为Jenkins源或Flow流水线时,必填。填写具体的Jenkins任务或Flow流水线构建编号。

触发事件

YAML 标识

备注

最后一次运行

lastBuild

Jenkins 源

最后一次成功运行

lastSuccessfulBuild

Jenkins 源或Flow 流水线

具体执行编号

构建编号数字

Jenkins 源或Flow 流水线

如:

sources:
  my_jenkins:
    type: jenkins
    jenkinsJob: job-test
    build: lastBuild

sources.<source_id>.repoType

当流水线源为packages制品源时必填,且repoType只支持通用制品类型:generic。

sources:
  my_repo:
    type: packages
    repoType: generic                                            
    repo: flow_generic_repo                
    artifact: Artifacts_1418394
    version: 2024-03-28-11-53-39
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.repo

当流水线源为packages制品源时必填,填写具体的仓库id,可以在packages.aliyun.com页面从仓库基本信息获取仓库id。

sources:
  my_repo:
    type: packages
    repoType: generic                                            
    repo: flow_generic_repo
    artifact: Artifacts_1418394      
    version: 2024-03-28-11-53-39
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.artifact

当流水线源为packages制品源时必填,填写具体的制品名称。

sources:
  my_repo:
    type: packages
    repoType: generic                                            
    repo: flow_generic_repo                
    artifact: Artifacts_1418394      
    version: 2024-03-28-11-53-39  
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.version

当流水线源为packages制品源时必填,填写具体的制品版本号。

sources:
  my_repo:
    type: packages
    repoType: generic                                            
    repo: flow_generic_repo                
    artifact: Artifacts_1418394      
    version: 2024-03-28-11-53-39  
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.region

当流水线源为ACR镜像源时必填,只能填写已支持的region。

sources:
  my_repo:
    type: acr
    region: cn-hangzhou
    instance: yunxiao
    namespace: default
    imageRepo: test
    imageTag: 2024-04-07-17-18-26-YAML        
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.instance

当流水线源为ACR镜像源时必填,填写当前服务连接下授权的企业版ACR实例名称。

sources:
  my_repo:
    type: acr
    region: cn-hangzhou
    instance: yunxiao
    namespace: default
    imageRepo: test
    imageTag: 2024-04-07-17-18-26-YAML
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.namespace

当流水线源为ACR镜像源时必填,填写实例下的某个命名空间。

sources:
  my_repo:
    type: acr
    region: cn-hangzhou
    instance: yunxiao
    namespace: default
    imageRepo: test
    imageTag: 2024-04-07-17-18-26-YAML
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.imageRepo

当流水线源为ACR镜像源时必填,填写命名空间下的镜像仓库名称。

sources:
  my_repo:
    type: acr
    region: cn-hangzhou
    instance: yunxiao
    namespace: default
    imageRepo: test
    imageTag: 2024-04-07-17-18-26-YAML
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.imageTag

当流水线源为ACR镜像源时必填,填写镜像仓库下的某个版本名称。

sources:
  my_repo:
    type: acr
    region: cn-hangzhou
    instance: yunxiao
    namespace: default
    imageRepo: test
    imageTag: 2024-04-07-17-18-26-YAML
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>

sources.<source_id>.versionFilter

非必填,指定运行ACR镜像源版本的过滤规则,请填写正则表达式。仅满足过滤规则的版本可以触发流水线运行,在手工触发、制品源webhook触发、定时触发、Webhook触发各场景均生效。

sources:
  my_repo:
    type: acr
    region: cn-hangzhou
    instance: yunxiao
    namespace: default
    imageRepo: test
    imageTag: 2024-04-07-17-18-26-YAML
    versionFilter: .*-YAML         # 仅可运行以 -YAML结尾的版本
    triggerEvents:
      - pushCompleted
      - scanCompleted
    certificate:
      type: serviceConnection
      serviceConnection: <your-service-connection-id>