Azure WebApp Self Hosted API Service
2024-03-28
說明
Azure Web Services & Web Apps
Azure DevOps
CI
Pipeline 選擇「ASP.NET Core (.NET Framework)」 需要主動加入 PublishPipelineArtifact 來儲存編譯後的 Artifact。
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifact: 'ArtifactName'
publishLocation: 'pipeline'
CD
Run on agent 將 Agent Specification 設定為 Widnows Server 2022 或 Latest。
Deploy Azure App Service 開啟 "Deploy to Slot or App Service Environment"
Website Test
cURL
curl -X POST https://localhost/rest -d "message=message" -F "file=@D:/image.png"
POSTMAN
choose "Body" and "form-data" with set key to "file" and select the file.
存取
"Web Apps" select "網路" and select "公用網路存取" select "已從選取虛擬網路和 IP 位址啟用"
將不相符的規則動作一律拒絕,接著設定允許的規則。