Azure pipeline 配置根据条件执行脚本
生活随笔
收集整理的這篇文章主要介紹了
Azure pipeline 配置根据条件执行脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Azure pipeline 配置根據條件執行腳本
Intro
我的應用通過 azure pipeline 來做持續集成,之前已經介紹了根據不同分支去打包不同的package,具體的就不再這里詳細介紹了,可以參考
Solution
來看一下修改之后的 azure-pipelines.yaml 示例配置吧:
steps: # ... - script: docker push $(latestImageName) displayName: 'Push latest image' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev')) - script: docker push $(stableImageName) displayName: 'Push stable image' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - task: SSH@0 displayName: 'Run shell inline on remote machine' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev')) inputs: sshEndpoint: 'weihanli-vm' runOptions: inline inline: | kubectl set image deployment/activityreservation activityreservation=$(imageName) --record=true當前面的 step 運行成功并且是 master 分支的 build 時,發布 tag 為 stable 的 docker 鏡像,如果是 dev 分支則發布 tag 為 latest 的 docker 鏡像,并且僅當當前分支為 dev 時才執行部署操作。
完整配置可以在 Github上獲取
CI 執行過程
上圖是一個 dev 分支的 build,從上面的截圖可以看到,只有 master 分支才執行的 step,沒有被執行,直接跳過了
Reference
<https://docs.microsoft.com/zh-cn/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml >
總結
以上是生活随笔為你收集整理的Azure pipeline 配置根据条件执行脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员修神之路--设计一套RPC框架并非
- 下一篇: 一键分享博客或新闻到Teams好友或频道