Gitlab yaml 到 azure pipelines yaml 文件

Gitlab yaml to azure pipelines yaml file

我正在尝试转换,但在阅读了一些资料后,我不确定如何将与 gitlab CI 一起使用的这部分 yaml 代码转换为 azure pipelines yaml:

build:
  stage: build
  script:
    - npm run build
  artifacts:
    paths:
      - dist
  only:
    - master

deploy:
  stage: deploy
  script:
    - npm i -g netlify-cli
    - netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod
  dependencies:
    - build
  only:
    - master

特别是我想在构建阶段设置工件路径,然后以某种方式在部署阶段设置它。

我的 azure-pipelines yaml 中现在的样子:

- script: |
    npm run build
  displayName: 'Build'

- script: |
    npm i -g netlify-cli
    netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod
  displayName: 'Deploy'

见下例:

variables:
  - name: netlify.site.id
    value: {value}
  - name: netlify.auth.token
    value: {token}

trigger:
- master

pool:
  vmImage: 'vs2017-win2016'

stages:
  - stage: Build
    jobs:
      - job: ARM
        steps:
        - script: npm -version
        - publish: $(System.DefaultWorkingDirectory)
          artifact: dist
  - stage: Deploy
    dependsOn: Build
    condition: succeeded()
    jobs:
      - job: APP
        steps:
        - bash: |
           npm i -g netlify-cli
           netlify deploy --site $(netlify.site.id) --auth $(netlify.auth.token) --prod

Tip1: 如果 netlify.auth.tokennetlify.site.id 的值对你来说非常私密,你不希望它在 public YAML。您可以将它们存储在 变量组 中。然后将 Variables 部分更改为:

variables:
  - group: {group name}

看到这个doc

Tip2:对于阶段依赖,可以在VSTS yaml中使用dependsOn关键字实现依赖。参见 this

提示3:在VSTS中,必须指定stagesjobssteps作为服务器的入口点编译相应的部分。

A stage is a collection of related jobs.

A job is a collection of steps to be run by an agent or on the server.

Steps are a linear sequence of operations that make up a job.

提示 4: 要使用 YAML 在 VSTS 中发布工件,有 2 种不同的格式。一个是我上面为你展示的。 publish 关键字是发布管道工件任务的快捷方式。

另一种格式,看这个Publishing artifacts