【问题标题】:Gitlab yaml to azure pipelines yaml fileGitlab yaml 到 azure 管道 yaml 文件
【发布时间】:2020-03-21 23:46:16
【问题描述】:

我正在尝试转换,但在阅读了一些资料后,我不确定如何将与 gitlab CI 一起使用的这部分 yaml 代码转换为 azure 管道 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'

【问题讨论】:

    标签: azure-devops continuous-integration azure-pipelines gitlab-ci continuous-deployment


    【解决方案1】:

    请看下面的示例:

    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
    

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

    variables:
      - group: {group name}
    

    看到这个doc

    提示2: 对于stage依赖,可以在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 种不同的格式。一个是我在上面为你展示的。 发布关键字是发布管道工件任务的快捷方式。

    另一种格式,看这个Publishing artifacts

    【讨论】:

    • 有没有办法在阶段之间保留文件夹?例如在 gitlab 中我可以这样保持:cache: paths: - node_modules/
    • @AlexT 如果阶段 B 依赖于阶段 A,那么他们可以使用工件在阶段之间传递文件夹。这是最常用的方法,这也是我的并且工作正常。您还需要其他场景吗?
    • 是的,我在这个问题中提出了问题:stackoverflow.com/questions/59085210/…
    • @AlexT,给了你 2 种方法来尝试。如果您对 VSTS 有任何疑问,请随时告诉我。
    猜你喜欢
    • 1970-01-01
    • 2020-01-21
    • 2021-07-01
    • 2020-06-22
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多