また、デプロイ センターでは、ユーザー割り当て ID を利用することで、より安全な OpenID Connect 認証を簡単に構成できます。 詳細については、ユーザー割り当て ID オプションに関する記事を参照してください。
必要なアクセス許可がお使いの Azure アカウントに与えられている場合、ユーザー割り当て ID を作成できます。 必要なアクセス許可がない場合、[ID] ドロップダウン メニューで既存のユーザー割り当てマネージド ID を選択できます。
Web サイト共同作成者ロールを利用すると、Azure 管理者と共同でユーザー割り当てマネージド ID を作成できます。
サブスクリプションとオブジェクト別に新しいロールの割り当てを作成します。 既定では、このロールの割り当ては既定のサブスクリプションに紐づけられます。
$subscriptionId をサブスクリプション ID に、$resourceGroupName をリソース グループ名に、$webappName を Web アプリ名に、$assigneeObjectId を生成された id に置き換えます。
Azure CLI を使用して Azure サブスクリプションを管理する方法について説明します。
Azure CLI
az role assignment create --role contributor --subscription$subscriptionId--assignee-object-id$assigneeObjectId--scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/sites/$webappName--assignee-principal-type ServicePrincipal
name:.NETCoreon:[push]permissions: id-token:write contents:readenv: 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 usejobs: build: runs-on:ubuntu-latest steps:# Checkout the repo - uses:actions/checkout@main - uses:azure/login@v2 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.NETCore uses:actions/setup-dotnet@v3 with: dotnet-version:${{env.DOTNET_VERSION}}# Run dotnet build and publish - name:dotnetbuildandpublish 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
name:DeployASP.NETMVCAppdeploytoAzureWebAppon:[push]permissions: id-token:write contents:readenv: 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 usejobs: build-and-deploy: runs-on:windows-latest steps:# checkout the repo - uses:actions/checkout@main - uses:azure/login@v2 with: client-id:${{secrets.AZURE_CLIENT_ID}} tenant-id:${{secrets.AZURE_TENANT_ID}} subscription-id:${{secrets.AZURE_SUBSCRIPTION_ID}} - name:InstallNuget uses:nuget/setup-nuget@v1 with: nuget-version:${{env.NUGET_VERSION}} - name:NuGettorestoredependenciesaswellasproject-specifictoolsthatarespecifiedintheprojectfile run:nugetrestore - name:AddmsbuildtoPATH uses:microsoft/setup-msbuild@v1.0.2 - name:RunMSBuild 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
name:BuildanddeployWARapptoAzureWebAppusingOpenIDConnectenv: JAVA_VERSION:'11'# set this to the Java version to use DISTRIBUTION:microsoft# set this to the Java distribution AZURE_WEBAPP_NAME:sampleapp# set this to the name of your web appon:[push]permissions: id-token:write contents:readjobs: build: runs-on:ubuntu-latest steps: - uses:actions/checkout@v4 - name:SetupJavaversion uses:actions/setup-java@v3.0.0 with: java-version:${{env.JAVA_VERSION}} distribution:${{env.DISTRIBUTION}} cache:'maven' - name:BuildwithMaven run:mvncleaninstall - name:LogintoAzure uses:azure/login@v2 with: client-id:${{secrets.AZURE_CLIENT_ID}} tenant-id:${{secrets.AZURE_TENANT_ID}} subscription-id:${{secrets.AZURE_SUBSCRIPTION_ID}} - name:DeploytoAzureWebApp id:deploy-to-webapp uses:azure/webapps-deploy@v3 with: app-name:${{env.AZURE_WEBAPP_NAME}} package:'*.war'
name:JavaScriptCIon:[push]permissions: id-token:write contents:readname:Node.jsenv: 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 usejobs: build-and-deploy: runs-on:ubuntu-latest steps:# checkout the repo - name:'Checkout GitHub Action' uses:actions/checkout@main - uses:azure/login@v2 with: client-id:${{secrets.AZURE_CLIENT_ID}} tenant-id:${{secrets.AZURE_TENANT_ID}} subscription-id:${{secrets.AZURE_SUBSCRIPTION_ID}} - name:SetupNode${{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
YAML
name:Pythonapplicationon:[push]permissions: id-token:write contents:readenv: 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 rootjobs: build: runs-on:ubuntu-latest steps: - uses:actions/checkout@v4 - uses:azure/login@v2 with: client-id:${{secrets.AZURE_CLIENT_ID}} tenant-id:${{secrets.AZURE_TENANT_ID}} subscription-id:${{secrets.AZURE_SUBSCRIPTION_ID}} - name:SetupPython3.x uses:actions/setup-python@v4 with: python-version:3.x - name:Installdependencies run:|
python -m pip install --upgrade pip
pip install -r requirements.txt
- name:DeploywebAppusingGHActionazure/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
name:.NETCoreCIon:[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 usejobs: build: runs-on:ubuntu-latest steps:# Checkout the repo - uses:actions/checkout@main# Setup .NET Core SDK - name:Setup.NETCore uses:actions/setup-dotnet@v3 with: dotnet-version:${{env.DOTNET_VERSION}}# Run dotnet build and publish - name:dotnetbuildandpublish 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'
NuGet と認証に publish-profile を使用する ASP.NET MVC アプリをビルドしてデプロイします。
YAML
name:DeployASP.NETMVCAppdeploytoAzureWebAppon:[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 usejobs: build-and-deploy: runs-on:windows-latest steps: - uses:actions/checkout@main - name:InstallNuget uses:nuget/setup-nuget@v1 with: nuget-version:${{env.NUGET_VERSION}} - name:NuGettorestoredependenciesaswellasproject-specifictoolsthatarespecifiedintheprojectfile run:nugetrestore - name:AddmsbuildtoPATH uses:microsoft/setup-msbuild@v1.0.2 - name:RunMSBuild 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/'
name:BuildanddeployWARapptoAzureWebAppusingpublishprofileenv: JAVA_VERSION:'11'# set this to the Java version to use DISTRIBUTION:microsoft# set this to the Java distribution AZURE_WEBAPP_NAME:sampleapp# set this to the name of your web appon:[push]permissions: id-token:write contents:readjobs: build: runs-on:ubuntu-latest steps: - uses:actions/checkout@v4 - name:SetupJavaversion uses:actions/setup-java@v3.0.0 with: java-version:${{env.JAVA_VERSION}} distribution:${{env.DISTRIBUTION}} cache:'maven' - name:BuildwithMaven run:mvncleaninstall - name:DeploytoAzureWebApp id:deploy-to-webapp uses:azure/webapps-deploy@v3 with: app-name:${{env.AZURE_WEBAPP_NAME}} publish-profile:${{secrets.AZURE_WEBAPP_PUBLISH_PROFILE}} package:'*.war'
# File: .github/workflows/workflow.ymlname:JavaScriptCIon:[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 usejobs: build-and-deploy: name:BuildandDeploy runs-on:ubuntu-latest steps: - uses:actions/checkout@main - name:UseNode.js${{env.NODE_VERSION}} uses:actions/setup-node@v4 with: node-version:${{env.NODE_VERSION}} - name:npminstall,build,andtest 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}}
name:PythonCIon:[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 rootjobs: build: runs-on:ubuntu-latest steps: - uses:actions/checkout@v4 - name:SetupPython3.x uses:actions/setup-python@v4 with: python-version:3.x - name:Installdependencies run:|
python -m pip install --upgrade pip
pip install -r requirements.txt
- name:Buildingwebapp uses:azure/appservice-build@v2 - name:DeploywebAppusingGHActionazure/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}}
name:.NETCoreon:[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 usejobs: build: runs-on:ubuntu-latest steps:# Checkout the repo - uses:actions/checkout@main - uses:azure/login@v2 with: creds:${{secrets.AZURE_CREDENTIALS}}# Setup .NET Core SDK - name:Setup.NETCore uses:actions/setup-dotnet@v3 with: dotnet-version:${{env.DOTNET_VERSION}}# Run dotnet build and publish - name:dotnetbuildandpublish 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
name:DeployASP.NETMVCAppdeploytoAzureWebAppon:[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 usejobs: build-and-deploy: runs-on:windows-latest steps:# checkout the repo - uses:actions/checkout@main - uses:azure/login@v2 with: creds:${{secrets.AZURE_CREDENTIALS}} - name:InstallNuget uses:nuget/setup-nuget@v1 with: nuget-version:${{env.NUGET_VERSION}} - name:NuGettorestoredependenciesaswellasproject-specifictoolsthatarespecifiedintheprojectfile run:nugetrestore - name:AddmsbuildtoPATH uses:microsoft/setup-msbuild@v1.0.2 - name:RunMSBuild 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
name:BuildanddeployWARapptoAzureWebAppusingServicePrincipalConnectenv: JAVA_VERSION:'11'# set this to the Java version to use DISTRIBUTION:microsoft# set this to the Java distribution AZURE_WEBAPP_NAME:sampleapp# set this to the name of your web appon:[push]permissions: contents:readjobs: build: runs-on:ubuntu-latest steps: - uses:actions/checkout@v4 - name:SetupJavaversion uses:actions/setup-java@v3.0.0 with: java-version:${{env.JAVA_VERSION}} distribution:${{env.DISTRIBUTION}} cache:'maven' - name:BuildwithMaven run:mvncleaninstall - name:LogintoAzure uses:azure/login@v2 with: creds:${{secrets.AZURE_CREDENTIALS}} - name:DeploytoAzureWebApp id:deploy-to-webapp uses:azure/webapps-deploy@v3 with: app-name:${{env.AZURE_WEBAPP_NAME}} package:'*.war'
name:JavaScriptCIon:[push]name:Node.jsenv: 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 usejobs: build-and-deploy: runs-on:ubuntu-latest steps:# checkout the repo - name:'Checkout GitHub Action' uses:actions/checkout@main - uses:azure/login@v2 with: creds:${{secrets.AZURE_CREDENTIALS}} - name:SetupNode${{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:Pythonapplicationon:[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 rootjobs: build: runs-on:ubuntu-latest steps: - uses:actions/checkout@v4 - uses:azure/login@v2 with: creds:${{secrets.AZURE_CREDENTIALS}} - name:SetupPython3.x uses:actions/setup-python@v4 with: python-version:3.x - name:Installdependencies run:|
python -m pip install --upgrade pip
pip install -r requirements.txt
- name:DeploywebAppusingGHActionazure/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
- uses:azure/appservice-settings@v1 with: app-name:'my-app' slot-name:'staging'# Optional and needed only if the settings have to be configured on the specific deployment slot app-settings-json:'[{ "name": "CATALINA_OPTS", "value": "-Dfoo=bar" }]' connection-strings-json:'${{ secrets.CONNECTION_STRINGS }}' general-settings-json:'{"alwaysOn": "false", "webSocketsEnabled": "true"}'#'General configuration settings as Key Value pairs' id:settings
このアクションに関する詳細と、その使用および構成方法については、App Service の設定リポジトリを参照してください。