Reputation: 731
I'd like to set the current GitHub commit SHA as an environment variable when deploying my application using webapps-deploy
: https://github.com/Azure/webapps-deploy
How can I achieve this?
My current yaml looks something like this:
# 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 }}
Upvotes: 0
Views: 602
Reputation: 8195
I tried below code to to set Commit SHA environment variable and it worked successfully in Python Azure Web app github action workflow.
My github action workflow:-
You can refer the complete workflow code here.
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 }}
Output:-
Upvotes: 1