我正在尝试为一个角度应用程序设置一个CI/CD管道。我从一本教程中获得了灵感(真遗憾,我关闭了浏览器选项卡,忘了在代码中添加一条值得称赞的评论),但最终还是安排了这样做:
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'xxx'
# Environment name
environmentName: 'xxx'
# Web app name
webAppName: 'xxx'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: BuildJob
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '14.x'
displayName: 'Install Node.js'
- task: Npm@1
inputs:
command: 'ci'
displayName: 'NPM CI'
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'install -g @angular/cli'
displayName: 'Install Angular'
- script: ng build --prod
displayName: 'build Angular'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/dist/App-FE'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
displayName: "Upload Artifacts"
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
ArtifactName: 'APP-FE'
publishLocation: 'Container'
- stage: Deploy
displayName: 'Deploy Web App'
dependsOn: Build
condition: succeeded()
jobs:
- deployment: DeploymentJob
pool:
vmImage: 'ubuntu-latest'
environment: $(environmentName)
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: 'Deploy Azure Web App : $(webAppName)'
inputs:
azureSubscription: $(azureSubscription)
appName: $(webAppName)
appType: webAppLinux
package: $(Pipeline.Workspace)/$(Build.BuildId).zip
问题发生在部署阶段。
理想情况下,我创建了一个用于处理的zip工件。
2021-03-04T16:48:35.1679914Z File upload succeed.
2021-03-04T16:48:35.1680158Z Upload '/home/vsts/work/1/a/4406.zip' to file container: '#/7437349/APP-FE'
然后,在部署阶段检索工件。
2021-03-04T16:48:56.3711666Z Downloading items from container resource #/7437349/APP-FE
2021-03-04T16:48:56.3712634Z Downloading artifact APP-FE from: https://dev.azure.com/xxx//_apis/resources/Containers/7437349?itemPath=APP-FE&isShallow=true&api-version=4.1-preview.4
2021-03-04T16:48:56.3725395Z Downloading APP-FE/4406.zip to /home/vsts/work/1/APP-FE/4406.zip
2021-03-04T16:48:56.3726090Z Downloaded APP-FE/4406.zip to /home/vsts/work/1/APP-FE/4406.zip
但这将在/home/vsts/work/1/APP-FE/
中下载一个与ArtifactName
匹配的文件。下一项工作失败
2021-03-04T16:48:57.8428994Z ##[error]Error: No package found with specified pattern: /home/vsts/work/1/4406.zip<br/>Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
正确的路径应该是/home/vsts/work/1/APP-FE/4406.zip
。我可能会对$(Pipeline.Workspace)/APP-FE/$(Build.BuildId).zip
路径进行硬编码,实际上我尝试过,但我想更好地理解引用新上传的工件的正确语法应该是什么。
请注意,如果通过硬编码路径更改管道,则修复此错误并进入下一个错误。
问题是关于理解如何构建一个干净、简单和正确的管道。
发布于 2021-03-04 09:23:32
工件名称将始终是路径的一部分,因为可以想象此部署之前的构建可能会发布多个工件。
因此,您的部署作业将需要提供工件路径,但您可以在变量部分中尝试这样做:
variables:
...
artifactName: 'APP-FE'
然后在发布阶段:
- task: PublishBuildArtifacts@1
displayName: "Upload Artifacts"
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
ArtifactName: $(artifactName)
publishLocation: 'Container'
然后在部署阶段:
- task: AzureWebApp@1
displayName: 'Deploy Azure Web App : $(webAppName)'
inputs:
azureSubscription: $(azureSubscription)
appName: $(webAppName)
appType: webAppLinux
package: $(Pipeline.Workspace)/$(artifactName)/$(Build.BuildId).zip
https://stackoverflow.com/questions/66479749
复制相似问题