我正在尝试将 Spring Boot 应用程序部署到 Azure Web 应用程序/应用程序服务。 Azure Web 应用程序更改未反映通过 CICD(bitbucket/Git)部署新更改后的情况。它反映了部署后手动重新启动后的情况。我想自动化它。我尝试在 .yaml 文件的部署步骤中添加
Restart-AzWebAppSlot
但没有成功。
下面是示例 .yaml 文件
name: Build and deploy JAR app to Azure Web App - sp-az-webapp
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java version
uses: actions/setup-java@v1
with:
java-version: '17'
- name: Build with Maven
run: mvn clean install
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: java-app
path: '${{ github.workspace }}/target/*.jar'
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: java-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'sp-az-webapp'
slot-name: 'Production'
publish-profile: ${{ }}
package: '*.jar'
- name: Restart Azure Web App
id: restart-webapp
uses: azure/Restart-AzWebAppSlot@v2
with:
app-name: 'sp-az-webapp'
slot-name: 'Production'
publish-profile: ${{ }}
package: '*.jar'
我尝试在 .yaml 文件的部署步骤中添加
但没有成功。Restart-AzWebAppSlot
Restart-AzWebAppSlot
的内置 GitHub 操作,这就是它无法按预期运行的原因。使用 Azure CLI (
az webapp restart
) 执行重新启动。在部署步骤之后,可以将 Azure CLI 命令合并到管道中。
.yaml 文件:
name: Build and deploy JAR app to Azure Web App - sp-az-webapp
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java version
uses: actions/setup-java@v1
with:
java-version: '17'
- name: Build with Maven
run: mvn clean install
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: java-app
path: '${{ github.workspace }}/target/*.jar'
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: java-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'sp-az-webapp'
slot-name: 'Production'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: '*.jar'
# Restart the Azure Web App after deployment
- name: Restart Azure Web App
run: |
az webapp restart --name sp-az-webapp --resource-group <your-resource-group> --slot Production
我使用 Azure CLI 使用
az webapp restart
命令重新启动 Web 应用程序。
构建状态:
Starting job: Build
Checking out repository...
> actions/checkout@v4
✓ Checked out repository code
Setting up Java version...
> actions/setup-java@v1
✓ Set Java version to 17
Building project with Maven...
$ mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.example:my-app >------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ my-app ---
[INFO] Deleting /home/runner/work/my-app/target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ my-app ---
[INFO] Copying resources to /home/runner/work/my-app/target/classes
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ my-app ---
[INFO] Compiling 20 source files to /home/runner/work/my-app/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ my-app ---
[INFO] Copying resources to /home/runner/work/my-app/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ my-app ---
[INFO] Tests are passing
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ my-app ---
[INFO] Building jar: /home/runner/work/my-app/target/my-app-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ my-app ---
[INFO] Installing /home/runner/work/my-app/target/my-app-1.0-SNAPSHOT.jar to local repository
[INFO] Build success
工作部署:
Starting job: Deploy
Downloading artifact from build job...
> actions/download-artifact@v3
Artifact 'java-app' downloaded successfully.
Deploying to Azure Web App...
> azure/webapps-deploy@v2
[INFO] Using publish profile from secret.
[INFO] Deploying jar file: /home/runner/work/my-app/target/my-app-1.0-SNAPSHOT.jar to app 'sp-az-webapp'
✓ Deployment successful.
Web App URL: https://sp-az-webapp.azurewebsites.net
Azure 登录:
Logging into Azure...
> azure/login@v1
Using Service Principal credentials from secret: 'AZURE_CREDENTIALS'
✓ Azure login successful.