azure - Azure YAML 脚本 - 生成和发布
问题描述
我们可以在 Azure DevOps 的同一个 YAML 脚本中构建和发布吗?如果是,有人可以帮我编写示例脚本吗?对于发布部分,我们正在部署到多个环境。
解决方案
我们有多种方式通过 Azure DevOps 启动构建和发布我们的配置。
首先,我们将着眼于以两种不同的 yml 格式构建 CI 和 CD,并创建两个管道来自动化我们的任务。为此,我们将在 YAML 管道中使用资源。
现在我们将通过创建新的 DevOps 项目和新的存储库来创建构建管道,可以在下面的 yaml 文件中添加 build-pipeline.yml
trigger:
branches:
include:
- master
paths:
exclude:
- build-pipeline.yml
- release-pipeline.yml
variables:
vmImageName: 'ubuntu-latest'
jobs:
- job: Build
pool:
vmImage: $(vmImageName)
steps:
- script: |
echo 'do some unit test'
displayName: 'unit test'
- script: |
echo 'compile application'
displayName: 'compile'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
同样,我们创建一个发布管道,下面是 yml 格式:
# Explicitly set none for repositry trigger
trigger:
- none
resources:
pipelines:
- pipeline: myappbuild # Name of the pipeline resource
source: myapp-build-pipeline # Name of the triggering pipeline
trigger:
branches:
- master
variables:
vmImageName: 'ubuntu-latest'
jobs:
- deployment: Deploy
displayName: Deploy
environment: dev
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- download: myappbuild
artifact: drop
- task: ExtractFiles@1
inputs:
archiveFilePatterns: '$(PIPELINE.WORKSPACE)/myappbuild/drop/$(resources.pipeline.myappbuild.runID).zip'
destinationFolder: '$(agent.builddirectory)'
cleanDestinationFolder: false
- script: |
cat $(agent.builddirectory)/greatcode.txt
在这里我们可以理解为先运行构建管道,然后运行发布管道,这些管道可以与多个部署链接。
此外,我们还有一些有用的博客的更多信息,例如c-sharpcorner、adamtheautomater。感谢博主。
推荐阅读
- php - 更新 apache "404 Not Found" 后无法访问我的网站
- php - PHP 如果未登录,停止加载视图的正确方法
- ssis - 使用 SSIS 删除和添加页眉和页脚进行读写
- c# - MVC - 如何在使用下拉列表时返回多个属性
- flutter - 如何启动'n'数量的功能并在按钮按下时停止它
- c++ - 有没有办法检查 C++ 中的一组三个数字中的任何两个数字是否相等
- neo4j - neo4j 匹配两个不同的关系并检索计数,同时避免笛卡尔积
- linux - Linux 中如何使用/不使用硬件上下文开关?
- python - multivariate_normal.pdf() 返回零?
- symfony - 我得到一个无效的令牌?