使用Azure的webapps-deploy GitHub Action将Git commit SHA设置为环境变量

kzipqqlq  于 2023-08-07  发布在  Git
关注(0)|答案(1)|浏览(97)

我想在使用webapps-deploy部署应用程序时将当前GitHub提交SHA设置为环境变量:https://github.com/Azure/webapps-deploy
我该如何实现这一点?
我现在的yaml看起来像这样:

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions

name: My App Deployment Pipeline

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Set up Python version
        uses: actions/setup-python@v3
        with:
          python-version: '3.9'

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate

      - name: Install dependencies
        run: |
          pip install -r requirements.txt
          python -m playwright install

      - name: Build Project
        run: |
          cd frontend
          npm ci
          npm run build

      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !venv/
            !frontend/node_modules/
          retention-days: 5

  deploy-staging:
    name: Deploy to staging
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'stage'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .

      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: 'my-app-name'
          slot-name: 'Production'
          publish-profile: ${{ secrets.publishprofile }}
          

  deploy-production:
    name: Deploy to production
    runs-on: ubuntu-latest
    needs: [build, deploy-staging]
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .

      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: 'my-app-name'
          slot-name: 'Production'
          publish-profile: ${{ secrets.publishprofile }}

字符串

whhtz7ly

whhtz7ly1#

我尝试了下面的代码来设置Commit SHA环境变量,它在Python Azure Web应用程序github操作工作流中成功工作。

我的github操作工作流程:-

完整的工作流代码可在此处参考。

name: Build and deploy Python app to Azure Web App - valleywebapp0

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Python version
        uses: actions/setup-python@v1
        with:
          python-version: '3.9'

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      
      - name: Install dependencies
        run: pip install -r requirements.txt
        
      
      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !venv/
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Set Commit SHA environment variable
        run:   echo "COMMIT_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
         
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .
          
      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: 'valleywebapp0'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_FBE0A8A87E804D00802E7E91678FC5E5 }}

字符串

输出:-

x1c 0d1x的数据

相关问题