Un account GitHub. Se non è disponibile, iscriversi per riceverne uno gratuito.
Configurare la distribuzione di GitHub Actions durante la creazione dell'app
La distribuzione di GitHub Actions è integrata nella creazione guidata di app predefinita. È sufficiente impostare Distribuzione continua su Abilita nella scheda Distribuzione e configurare l'organizzazione, il repository e il ramo desiderati.
Quando si abilita la distribuzione continua, la creazione guidata dell'app seleziona automaticamente il metodo di autenticazione in base alla selezione dell'autenticazione di base e configura l'app e il repository GitHub di conseguenza:
Configurare la distribuzione di GitHub Actions dal Centro distribuzione
Per un'app esistente, è possibile iniziare rapidamente a usare GitHub Actions usando servizio app Deployment Center. Questo metodo turn-key genera automaticamente un file del flusso di lavoro di GitHub Actions basato sullo stack di applicazioni ed esegue il commit nel repository GitHub.
Il Centro distribuzione consente anche di configurare facilmente l'autenticazione OpenID più sicura Connessione con l'opzione di identità assegnata dall'utente.
Se l'account Azure dispone delle autorizzazioni necessarie, è possibile selezionare per creare un'identità assegnata dall'utente. In caso contrario, è possibile selezionare un'identità gestita assegnata dall'utente esistente nell'elenco a discesa Identità . È possibile collaborare con l'amministratore di Azure per creare un'identità gestita assegnata dall'utente con il ruolo Collaboratore sito Web.
Il modo consigliato per eseguire l'autenticazione con i servizi di app Azure per GitHub Actions è con un'identità gestita definita dall'utente e il modo più semplice per eseguire questa operazione consiste nella configurazione della distribuzione di GitHub Actions direttamente nel portale e nella selezione dell'identità gestita assegnata dall'utente.
Nota
L'autenticazione con un'identità gestita assegnata dall'utente è attualmente in anteprima.
In alternativa, è possibile eseguire l'autenticazione con un'entità servizio, un Connessione OpenID o un profilo di pubblicazione.
Un profilo di pubblicazione è una credenziale a livello di app. Configurare il profilo di pubblicazione come segreto GitHub.
Passare al servizio app nel portale di Azure.
Nella pagina Panoramica selezionare Recupera profilo di pubblicazione.
Salvare il file scaricato. Si userà il contenuto del file per creare un segreto GitHub.
Nota
A partire da ottobre 2020, le app Web Linux devono avere l'impostazione dell'app impostata WEBSITE_WEBDEPLOY_USE_SCM su trueprima di scaricare il profilo di pubblicazione. Questo requisito verrà rimosso in futuro.
az ad sp create-for-rbac --name "myApp" --role contributor \
--scopes /subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.Web/sites/<app-name> \
--json-auth
Nell'esempio precedente sostituire i segnaposto con l'ID sottoscrizione, il nome del gruppo di risorse e il nome dell'app. L'output è un oggetto JSON con le credenziali di assegnazione di ruolo che forniscono l'accesso all'app servizio app simile al frammento JSON seguente. Copiare l'oggetto JSON per un uso successivo.
È sempre consigliabile concedere l'accesso minimo. L'ambito nell'esempio precedente è limitato all'app servizio app specifica e non all'intero gruppo di risorse.
OpenID Connessione è un metodo di autenticazione che usa token di breve durata. La configurazione di OpenID Connessione con GitHub Actions è più complessa, ma offre sicurezza avanzata.
Se non si dispone di un'applicazione esistente, registrare una nuova applicazione Active Directory e un'entità servizio in grado di accedere alle risorse. Creare l'applicazione Active Directory.
az ad app create --display-name myApp
Questo comando restituisce un codice JSON con un oggetto appId che corrisponde a client-id. Salvare il valore da usare come AZURE_CLIENT_ID segreto GitHub in un secondo momento.
Si userà il objectId valore quando si creano credenziali federate con l'API APPLICATION-OBJECT-IDGraph e si farà riferimento come .
Creare un'entità servizio. Sostituire con il $appID valore appId dall'output JSON.
Questo comando genera un output JSON diverso objectId e verrà usato nel passaggio successivo. Il nuovo objectId è .assignee-object-id
Copiare da appOwnerTenantId usare come segreto GitHub per AZURE_TENANT_ID un secondo momento.
az ad sp create --id $appId
Creare una nuova assegnazione di ruolo per sottoscrizione e oggetto. Per impostazione predefinita, l'assegnazione di ruolo è associata alla sottoscrizione predefinita. Sostituire $subscriptionId con l'ID sottoscrizione, $resourceGroupName con il nome del gruppo di risorse e $assigneeObjectId con l'oggetto generato assignee-object-id. Informazioni su come gestire le sottoscrizioni di Azure con l'interfaccia della riga di comando di Azure.
az role assignment create --role contributor --subscription $subscriptionId --assignee-object-id $assigneeObjectId --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/sites/ --assignee-principal-type ServicePrincipal
Eseguire il comando seguente per creare una nuova credenziale di identità federata per l'applicazione Active Directory.
Sostituire APPLICATION-OBJECT-ID con objectId (generato durante la creazione dell'app) per l'applicazione Active Directory.
Impostare un valore per CREDENTIAL-NAME per fare riferimento in un secondo momento.
Impostare subject. Il valore è definito da GitHub a seconda del flusso di lavoro:
Processi nell'ambiente GitHub Actions: repo:< Organization/Repository >:environment:< Name >
Per i processi non associati a un ambiente, includere il percorso di riferimento per branch/tag in base al percorso di riferimento usato per attivare il flusso di lavoro: repo:< Organization/Repository >:ref:< ref path>. Ad esempio, repo:n-username/ node_express:ref:refs/heads/my-branch o repo:n-username/ node_express:ref:refs/tags/my-tag.
Per i flussi di lavoro attivati da un evento di richiesta pull: repo:< Organization/Repository >:pull_request.
az ad app federated-credential create --id <APPLICATION-OBJECT-ID> --parameters credential.json
("credential.json" contains the following content)
{
"name": "<CREDENTIAL-NAME>",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:organization/repository:ref:refs/heads/main",
"description": "Testing",
"audiences": [
"api://AzureADTokenExchange"
]
}
Per informazioni su come creare un'applicazione active directory, un'entità servizio e le credenziali federate in portale di Azure, vedere Connessione GitHub e Azure.
In GitHub esplorare il repository. Selezionare Impostazioni > Segreti di sicurezza > e variabili > Azioni > Nuovo segreto del repository.
Per usare le credenziali a livello di app, incollare il contenuto del file del profilo di pubblicazione scaricato nel campo valore del segreto. Assegnare al segreto AZURE_WEBAPP_PUBLISH_PROFILEil nome .
Quando si configura il file del flusso di lavoro GitHub in un secondo momento, usare AZURE_WEBAPP_PUBLISH_PROFILE nell'azione deploy Azure Web App (Distribuisci app Web di Azure). Ad esempio:
In GitHub esplorare il repository. Selezionare Impostazioni > Segreti di sicurezza > e variabili > Azioni > Nuovo segreto del repository.
Per usare le credenziali a livello di utente, incollare l'intero output JSON dal comando dell'interfaccia della riga di comando di Azure nel campo valore del segreto. Assegnare al segreto AZURE_CREDENTIALSil nome .
Quando si configura il file del flusso di lavoro GitHub in un secondo momento, si usa il segreto per l'input credsdi Azure/login. Ad esempio:
È necessario specificare l'ID client, l'ID tenant e l'ID sottoscrizione dell'applicazione all'azione Azure/login. Questi valori possono essere forniti direttamente nel flusso di lavoro o possono essere archiviati nei segreti gitHub e a cui si fa riferimento nel flusso di lavoro. Il salvataggio dei valori come segreti GitHub è l'opzione più sicura.
Aprire il repository GitHub e passare a Impostazioni > Segreti di sicurezza > e variabili > Azioni > Nuovo segreto del repository.
Creare segreti per AZURE_CLIENT_ID, AZURE_TENANT_IDe AZURE_SUBSCRIPTION_ID. Usare questi valori dell'applicazione Active Directory per i segreti di GitHub:
Segreto GitHub
Applicazione Active Directory
AZURE_CLIENT_ID
ID applicazione (client)
AZURE_TENANT_ID
ID della directory (tenant)
AZURE_SUBSCRIPTION_ID
ID sottoscrizione
Salvare ogni segreto selezionando Aggiungi segreto.
3. Aggiungere il file del flusso di lavoro al repository GitHub
Un flusso di lavoro viene definito da un file YAML (.yml) nel /.github/workflows/ percorso nel repository GitHub. Questa definizione contiene i vari passaggi e i parametri che costituiscono il flusso di lavoro.
Come minimo, il file del flusso di lavoro avrà i passaggi distinti seguenti:
Eseguire l'autenticazione con servizio app usando il segreto GitHub creato.
Compilare l'app Web.
Distribuire l'app Web.
Per distribuire il codice in un'app servizio app, usare l'azione azure/webapps-deploy@v3. L'azione richiede il nome dell'app Web in app-name e, a seconda dello stack di linguaggio, il percorso di un *.zip, *.war, *.jar o cartella da distribuire in package. Per un elenco completo dei possibili input per l'azione azure/webapps-deploy@v3 , vedere la definizione di action.yml .
Negli esempi seguenti viene mostrata la parte del flusso di lavoro che compila l'app Web, in lingue supportate diverse.
name: .NET Core CI
on: [push]
env:
AZURE_WEBAPP_NAME: my-app-name # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '6.0.x' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@main
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release --property:PublishDir='${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
Compilare e distribuire un'app MVC ASP.NET che usa NuGet e publish-profile per l'autenticazione.
name: Deploy ASP.NET MVC App deploy to Azure Web App
on: [push]
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NUGET_VERSION: '5.3.x' # set this to the dot net version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- uses: actions/checkout@main
- name: Install Nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: ${{ env.NUGET_VERSION}}
- name: NuGet to restore dependencies as well as project-specific tools that are specified in the project file
run: nuget restore
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Run MSBuild
run: msbuild .\SampleWebApplication.sln
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/SampleWebApplication/'
Compilare e distribuire un'app Java Spring in Azure usando un profilo di pubblicazione di Azure. L'input publish-profile fa riferimento al AZURE_WEBAPP_PUBLISH_PROFILE segreto creato in precedenza.
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: my-app-path
- name: Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: my-app-name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: my/target/*.jar
Per distribuire un oggetto war anziché un oggetto jar, modificare il package valore.
Compilare e distribuire un'app Node.js in Azure usando il profilo di pubblicazione dell'app. L'input publish-profile fa riferimento al AZURE_WEBAPP_PUBLISH_PROFILE segreto creato in precedenza.
# File: .github/workflows/workflow.yml
name: JavaScript CI
on: [push]
env:
AZURE_WEBAPP_NAME: my-app-name # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: 'my-app-path' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '18.x' # set this to the node version to use
jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: npm install, build, and test
run: |
# Build and test the project, then
# deploy to Azure Web App.
npm install
npm run build --if-present
npm run test --if-present
working-directory: my-app-path
- name: 'Deploy to Azure WebApp'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Compilare e distribuire un'app Python in Azure usando il profilo di pubblicazione dell'app. Si noti che l'input publish-profile fa riferimento al AZURE_WEBAPP_PUBLISH_PROFILE segreto creato in precedenza.
name: Python CI
on:
[push]
env:
AZURE_WEBAPP_NAME: my-web-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Building web app
uses: azure/appservice-build@v2
- name: Deploy web App using GH Action azure/webapps-deploy
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Per eseguire la distribuzione con l'entità servizio configurata, usare l'azione azure/login@v1 con la creds chiave e fare riferimento al AZURE_CREDENTIALS segreto creato in precedenza.
name: .NET Core
on: [push]
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '6.0.x' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release --property:PublishDir='${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using Azure Credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
- name: logout
run: |
az logout
Compilare e distribuire un'app MVC ASP.NET in Azure usando un'entità servizio di Azure. Si noti che l'input creds fa riferimento al AZURE_CREDENTIALS segreto creato in precedenza.
name: Deploy ASP.NET MVC App deploy to Azure Web App
on: [push]
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NUGET_VERSION: '5.3.x' # set this to the dot net version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
# checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Install Nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: ${{ env.NUGET_VERSION}}
- name: NuGet to restore dependencies as well as project-specific tools that are specified in the project file
run: nuget restore
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Run MSBuild
run: msbuild .\SampleWebApplication.sln
- name: 'Run Azure webapp deploy action using Azure Credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/SampleWebApplication/'
# Azure logout
- name: logout
run: |
az logout
Compilare e distribuire un'app Java Spring in Azure usando un'entità servizio di Azure. Si noti che l'input creds fa riferimento al AZURE_CREDENTIALS segreto creato in precedenza.
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: complete
- name: Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: my-app-name
package: my/target/*.jar
# Azure logout
- name: logout
run: |
az logout
Compilare e distribuire un'app Node.js in Azure usando un'entità servizio di Azure. Si noti che l'input creds fa riferimento al AZURE_CREDENTIALS segreto creato in precedenza.
name: JavaScript CI
on: [push]
name: Node.js
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: 'my-app-path' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '18.x' # set this to the node version to use
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'npm install, build, and test'
run: |
npm install
npm run build --if-present
npm run test --if-present
working-directory: my-app-path
# deploy web app using Azure credentials
- uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
# Azure logout
- name: logout
run: |
az logout
Compilare e distribuire un'app Python in Azure usando un'entità servizio di Azure. Si noti che l'input creds fa riferimento al AZURE_CREDENTIALS segreto creato in precedenza.
name: Python application
on:
[push]
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Deploy web App using GH Action azure/webapps-deploy
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: logout
run: |
az logout
Per eseguire la distribuzione con OpenID Connessione usando l'identità gestita configurata, usare l'azione azure/login@v1 con le client-idchiavi , tenant-ide e subscription-id fare riferimento ai segreti GitHub creati in precedenza.
name: .NET Core
on: [push]
permissions:
id-token: write
contents: read
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '6.0.x' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release --property:PublishDir='${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
- name: logout
run: |
az logout
Compilare e distribuire un'app MVC ASP.NET in Azure usando un'entità servizio di Azure. Nell'esempio vengono usati segreti GitHub per i client-idvalori , tenant-ide subscription-id . È anche possibile passare questi valori direttamente nell'azione di accesso.
name: Deploy ASP.NET MVC App deploy to Azure Web App
on: [push]
permissions:
id-token: write
contents: read
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NUGET_VERSION: '5.3.x' # set this to the dot net version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
# checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Install Nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: ${{ env.NUGET_VERSION}}
- name: NuGet to restore dependencies as well as project-specific tools that are specified in the project file
run: nuget restore
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Run MSBuild
run: msbuild .\SampleWebApplication.sln
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/SampleWebApplication/'
# Azure logout
- name: logout
run: |
az logout
Compilare e distribuire un'app Java Spring in Azure usando un'entità servizio di Azure. Nell'esempio vengono usati segreti GitHub per i client-idvalori , tenant-ide subscription-id . È anche possibile passare questi valori direttamente nell'azione di accesso.
name: JavaScript CI
on: [push]
permissions:
id-token: write
contents: read
name: Node.js
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: 'my-app-path' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '18.x' # set this to the node version to use
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'npm install, build, and test'
run: |
npm install
npm run build --if-present
npm run test --if-present
working-directory: my-app-path
# deploy web app using Azure credentials
- uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
# Azure logout
- name: logout
run: |
az logout
name: Python application
on:
[push]
permissions:
id-token: write
contents: read
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Deploy web App using GH Action azure/webapps-deploy
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: logout
run: |
az logout
Passaggi successivi
Vedere i riferimenti in Azure GitHub Actions e nei flussi di lavoro: