prem build agent BUILD_ARTIFACTSTAGINGDIRECTORY 路径上 azure 中的随机数的预定义构建变量名称是什么
What is the predefined build variable name for the random number in azure on on prem build agent BUILD_ARTIFACTSTAGINGDIRECTORY path
我使用本地代理设置了 azure 管道。我需要知道预定义变量才能在 **BUILD_ARTIFACTSTAGINGDIRECTORY**
= C:\Users\Administrator\agent_work\a 中获取随机数(即)78 在此路径中。
我看了看Predefined Variables,但能找到这个。
我也关注了这个。但是那个 78 没有在任何变量中定义。
请问谁能帮忙找到变量?
构建目录 ID 没有预定义变量。将此 id 作为变量获取的另一种方法是在管道 运行.
期间从 $(Agent.BuildDirectory)
中提取它
如果您使用的是 Linux
环境,您可以这样做:
export BUILD_DIRECTORY_ID=$(echo $(Agent.BuildDirectory) | sed 's|.*\/||)
如果您使用的是Windows
环境:
$build_id = (echo $(Agent.BuildDirectory) | %{$_ -replace "(?s)^.*\", ""})
[Environment]::SetEnvironmentVariable("BUILD_DIRECTORY_ID", $build_id, "User")
I need to know the predefined variable to get the random number.
78
不是预定义变量,因此我们不能使用已记录的预定义变量来表示它。
此外,这不是随机数。每次我们在特定代理上创建新管道和 运行 管道时,它都会在 agent_work
或 _work
文件夹下创建一个新的 number-folder
。
关于 78
的一些细节:
我曾经使用代理 运行 六个不同的管道,所以我的 _work
文件夹下有六个文件夹(与您的 agent_work
文件夹相同)。如果我创建一个新的构建管道,然后 运行 使用此代理的管道,那么我将获得新文件夹 7
。所以这里每一个number folder
都可以代表一个pipeline
他们的秘密存储在 SourceRootMapping
文件夹中。其下的Mappings.json
文件记录了最后一次构建号,每次创建新文件夹时它都会增加。你可以找到许多以 BuildDefinitionID
命名的文件夹,在其中你可以找到 SourceFolder.json
文件,其中的信息是:
- number文件夹与对应pipeline的关系
- 代理目录,AgentArtifactstagingDir,...
- 上次 运行 时间、RepoID、OrgID、ProjectID...
Please can anyone assist on how to find the variable?
现在 Agent.BuildDirectory
变量是最接近您需要的文件夹编号的。因此,您可以在管道的开头添加一个 Powershell 内联任务以获取文件夹编号。我的 PS 脚本:
#Get the FolderID so that following commands in this task can use it via $FolderID.
$FolderID = Split-Path "$(Agent.BuildDirectory)" -Leaf
#Check its value.
Write-Host $FolderID
#Set it as job-scoped variable so that following ateps/tasks can use it via $(FolderID).
Write-Host "##vso[task.setvariable variable=FolderID]$FolderID"
在管道的第一个执行此脚本,然后后续任务 可以通过$(FolderID)
访问自定义变量。要在 第一个 PS 任务 中使用 FolderID,您应该改用 $FolderID。
我使用本地代理设置了 azure 管道。我需要知道预定义变量才能在 **BUILD_ARTIFACTSTAGINGDIRECTORY**
= C:\Users\Administrator\agent_work\a 中获取随机数(即)78 在此路径中。
我看了看Predefined Variables,但能找到这个。
我也关注了这个
请问谁能帮忙找到变量?
构建目录 ID 没有预定义变量。将此 id 作为变量获取的另一种方法是在管道 运行.
期间从$(Agent.BuildDirectory)
中提取它
如果您使用的是 Linux
环境,您可以这样做:
export BUILD_DIRECTORY_ID=$(echo $(Agent.BuildDirectory) | sed 's|.*\/||)
如果您使用的是Windows
环境:
$build_id = (echo $(Agent.BuildDirectory) | %{$_ -replace "(?s)^.*\", ""})
[Environment]::SetEnvironmentVariable("BUILD_DIRECTORY_ID", $build_id, "User")
I need to know the predefined variable to get the random number.
78
不是预定义变量,因此我们不能使用已记录的预定义变量来表示它。
此外,这不是随机数。每次我们在特定代理上创建新管道和 运行 管道时,它都会在 agent_work
或 _work
文件夹下创建一个新的 number-folder
。
关于 78
的一些细节:
我曾经使用代理 运行 六个不同的管道,所以我的 _work
文件夹下有六个文件夹(与您的 agent_work
文件夹相同)。如果我创建一个新的构建管道,然后 运行 使用此代理的管道,那么我将获得新文件夹 7
。所以这里每一个number folder
都可以代表一个pipeline
他们的秘密存储在 SourceRootMapping
文件夹中。其下的Mappings.json
文件记录了最后一次构建号,每次创建新文件夹时它都会增加。你可以找到许多以 BuildDefinitionID
命名的文件夹,在其中你可以找到 SourceFolder.json
文件,其中的信息是:
- number文件夹与对应pipeline的关系
- 代理目录,AgentArtifactstagingDir,...
- 上次 运行 时间、RepoID、OrgID、ProjectID...
Please can anyone assist on how to find the variable?
现在 Agent.BuildDirectory
变量是最接近您需要的文件夹编号的。因此,您可以在管道的开头添加一个 Powershell 内联任务以获取文件夹编号。我的 PS 脚本:
#Get the FolderID so that following commands in this task can use it via $FolderID.
$FolderID = Split-Path "$(Agent.BuildDirectory)" -Leaf
#Check its value.
Write-Host $FolderID
#Set it as job-scoped variable so that following ateps/tasks can use it via $(FolderID).
Write-Host "##vso[task.setvariable variable=FolderID]$FolderID"
在管道的第一个执行此脚本,然后后续任务 可以通过$(FolderID)
访问自定义变量。要在 第一个 PS 任务 中使用 FolderID,您应该改用 $FolderID。