E. *_*fan 4 azure azure-devops azure-pipelines azure-pipelines-yaml
我正在使用 Azure DevOps 构建 python 轮。我想让它尽可能通用,以便团队中的每个人都可以使用相同的管道来构建自己的 python 轮并将它们部署在一些 databricks 工作区中。为此,我需要知道构建管道输出中的文件名是什么,以便在我的发布管道中使用它。
目前在这种情况下,该文件是保存在构建管道输出中的 python 轮。我在管道 yaml 中使用以下代码在构建管道输出和 Azure 工件源中发布它。
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: dfordbx
- task: UniversalPackages@0
displayName: Publish
inputs:
command: publish
publishDirectory: $(Build.ArtifactStagingDirectory)/dist/
vstsFeedPublish: 'MyProject/py_artifacts_1732'
vstsFeedPackagePublish: $(packageBuildName)
Run Code Online (Sandbox Code Playgroud)
构建管道运行结束后,dist文件夹中会出现一个wheel文件。我需要得到这个轮子的名称。对于我自己的代码,我当然知道名字。但是当其他人为他们的代码运行管道时,我不清楚这一点。我需要在我的发布管道中获取这个名称。
换句话说,我正在我的 yaml 文件中寻找一种方法来获取以下结构中的“py_sample_package-0.6.5-py3-none-any.whl”名称:
通过选择已发布的工件:
获取文件:
突出显示的部分是我需要进入管道的部分。谢谢。
在经典发布管道中,您引用构建工件并将其用作触发器。工件被下载到$(System.DefaultWorkingDirectory)\$(Build.DefinitionName)
.
要识别.whl
工件中的文件,请将 powershell 脚本添加到您的发布管道中,该脚本可识别该文件并使用日志 ##vso
记录语法创建一个新变量...
例如:
# find the first .whl file in the artifact folder
$whlFile = Get-ChildItem `
-Filter *.whl `
-Path "$(System.DefaultWorkingDirectory)\$(Build.DefinitionName)\dfordbx" |
ForEach-Object { $_.fullname } |
Select-Object -First 1
# create a variable with the full path to the file
Write-Host "##vso[task.setvariable variable=whlFile]$whlFile"
Run Code Online (Sandbox Code Playgroud)
现在您可以像任何其他定义的管道变量一样使用该变量$(whlFile)
如果您使用多阶段 YAML 管道并且需要在阶段之间使用工件,则不能假设该文件将存在于计算机上,因为每个作业可能在不同的计算机上运行。您需要在作业开始时下载工件。
# find the first .whl file in the artifact folder
$whlFile = Get-ChildItem `
-Filter *.whl `
-Path "$(System.DefaultWorkingDirectory)\$(Build.DefinitionName)\dfordbx" |
ForEach-Object { $_.fullname } |
Select-Object -First 1
# create a variable with the full path to the file
Write-Host "##vso[task.setvariable variable=whlFile]$whlFile"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4161 次 |
最近记录: |