gpt4 book ai didi

azure - 排除 Azure CI 管道 (YAML) 中的某些文件

转载 作者:行者123 更新时间:2023-12-02 23:12:49 25 4
gpt4 key购买 nike

我有一个 CI 管道 (YAML),它构建了一个将部署到现有 Azure Function 中的存储库。 CI 管道正在做这件事。但是,完成后,我转到 Function App -> App files -> 我可以看到 azure-pipeline.yml 包含在其中(或者我认为它包含在构建过​​程中)。我尝试过使用路径和排除,但它们不起作用。我的问题是,如何仅排除 azure-pipeline.yml,以便在管道构建完成后,azure-pipeline.yml 不在 Function App 的应用程序文件中。下面是我的 YAML

trigger:
branches:
include:
- master
paths:
exclude:
- README.md
- azure-pipelines.yml

variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'DevOps-Test'
# Function app name
functionAppName: 'test'
# Agent VM image name
vmImageName: 'vs2017-win2016'
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/'


stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- powershell: |
if (Test-Path "extensions.csproj") {
dotnet build extensions.csproj --output ./$(workingDirectory)/bin
}
displayName: 'Build extensions'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: $(workingDirectory)
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionApp
appName: $(functionAppName)
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'

最佳答案

以下语法意味着文件 README.mdazure-pipelines.yml 不会触发构建。这并不意味着文件 README.mdazure-pipelines.yml 被排除在工作目录中。

trigger:
branches:
include:
- master
paths:
exclude:
- README.md
- azure-pipelines.yml

我注意到您尝试归档文件夹$(workingDirectory),并在变量中定义workingDirectory,该变量实际上是$(System.DefaultWorkingDirectory)/. System.DefaultWorkingDirectory 是代理上下载源代码文件的本地路径。

显然,文件 README.mdazure-pipelines.yml 位于源代码中,因此它们也被存档。您可以在 ArchiveFiles 任务 之前添加一个 CopyFiles 任务,以使用匹配模式将所需文件从源文件夹复制到目标文件夹,然后存档目标文件夹。例如:

- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory) '
inputs:
SourceFolder: '$(workingDirectory)'
Contents: |
**/*
!*.md
!*.yml
TargetFolder: '$(Build.ArtifactStagingDirectory) '

- task: ArchiveFiles@2
displayName: 'Archive files '
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory) '

关于azure - 排除 Azure CI 管道 (YAML) 中的某些文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65220679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com