问题描述
我的设置如下我已经托管了代理,作为第一项工作,它从以Docker容器启动的自托管代理复制文件
通过管道运行"来触发托管管道. rest API:https://docs.microsoft.com/zh-cn/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0
这是现在的身体样子:
"resources": {
"repositories:": {
"self": {
"refName": "refs/heads/my_branch"
}
}
}
效果很好.
现在托管管道的部分如下所示:
- job: self_hosted_connect
timeoutInMinutes: 10
pool: Default
steps:
- task: CopyFiles@2
inputs:
SourceFolder: '/home/copy_dir'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
也很好,
我的问题是:
-
我喜欢发送"run"消息rest API另一个包含SourceFolder路径的参数这样CopyFiles任务将是动态的,并且没有硬代码SourceFolder路径
-
当我从docker运行自托管代理时,如何告诉自托管代理在其工作目录之外包含目录?因此管道不会因错误而失败:
#[错误]未处理:找不到SourceFolder:/home/copy_dir
更新我将请求更新为:
{
"resources": {
"repositories:": {
"self": {
"refName": "refs/heads/my_branch"
}
}
},
"templateParameters": {
"Folderpath":"{/home/foo/my_dir}"
}
}
但是我遇到了错误:
{
"$id": "1",
"innerException": null,
"message": "Unexpected parameter 'Folderpath'",
"typeName": "Microsoft.Azure.Pipelines.WebApi.PipelineValidationException, Microsoft.Azure.Pipelines.WebApi",
"typeKey": "PipelineValidationException",
"errorCode": 0,
"eventId": 3000
}
YAML示例:
parameters:
- name: Folderpath
displayName: 'configure Folder path'
type: string
default: {SourceFolder path}
steps:
- task: CopyFiles@2
inputs:
SourceFolder: '${{ parameters.Folderpath}}'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
请求网址:
POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
请求正文:
{
"resources":{
"repositories":{
"self":{"refName":"refs/heads/{my_branch}"
}
}
},
"templateParameters": {
"Folderpath":"{SourceFolder path}"
}
}
我们可以复制本地文件夹或Azure DevOps 预定义的变量来定义源文件夹.
更新1
我们应该在YAML构建中定义参数,否则,我们将收到错误的意外参数'Folderpath''
更新2
我喜欢从自托管的docker光盘上的真实路径(我在请求中传递的路径)获取运行,而不是相对于docker工作目录,所以现在它给了我这个错误:
[error]Unhandled: Not found SourceFolder: /azp/agent/_work/1/s/{/home/copy_dir}
其中/azp是docker工作目录
我通过此链接配置了docker:
https://docs.microsoft. com/en-us/azure/devops/pipelines/agents/docker?view = azure-devops
my set up is as followI have hosted agent that as first job copies files from the self-hosted agent which is started as a docker container
the hosted pipeline is triggered with pipeline "run" rest API :
https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0
this is how the body looks like now :
"resources": {
"repositories:": {
"self": {
"refName": "refs/heads/my_branch"
}
}
}
it is working great.
now the part of the hosted pipeline looks like this :
- job: self_hosted_connect
timeoutInMinutes: 10
pool: Default
steps:
- task: CopyFiles@2
inputs:
SourceFolder: '/home/copy_dir'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
also, work great.
My questions are :
I like to send in the "run" rest API another parameter that contains the SourceFolder pathso that the CopyFiles task will be dynamic and not have hardcode SourceFolder path
When i run the self-hosted agent from docker how do i tell the self-hosted agent to include the directory outside its working dir? so the pipeline will not fail with the error :
#[error]Unhandled: Not found SourceFolder: /home/copy_dir
UPDATEi updated the request to :
{
"resources": {
"repositories:": {
"self": {
"refName": "refs/heads/my_branch"
}
}
},
"templateParameters": {
"Folderpath":"{/home/foo/my_dir}"
}
}
but I'm getting an error:
{
"$id": "1",
"innerException": null,
"message": "Unexpected parameter 'Folderpath'",
"typeName": "Microsoft.Azure.Pipelines.WebApi.PipelineValidationException, Microsoft.Azure.Pipelines.WebApi",
"typeKey": "PipelineValidationException",
"errorCode": 0,
"eventId": 3000
}
YAML sample:
parameters:
- name: Folderpath
displayName: 'configure Folder path'
type: string
default: {SourceFolder path}
steps:
- task: CopyFiles@2
inputs:
SourceFolder: '${{ parameters.Folderpath}}'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
Request URL:
POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
Request Body:
{
"resources":{
"repositories":{
"self":{"refName":"refs/heads/{my_branch}"
}
}
},
"templateParameters": {
"Folderpath":"{SourceFolder path}"
}
}
We can copy the local folder or azure DevOps predefined variables to define the source folder.
Update1
We should define the parameter in the YAML build, if not, we will get the error Unexpected parameter 'Folderpath'"
UPDATE 2
as i like it to take from the real path (the one i pass in the request ) on the disc where the self-hosted dockerrunning and not relative to the docker working dir, so now it gives me this error :
[error]Unhandled: Not found SourceFolder: /azp/agent/_work/1/s/{/home/copy_dir}
where /azp is the docker working dir
i configured docker from this link :
https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops
这篇关于Azure devops管道restAPI如何通过SourceFolder传递CopyFiles Task容器中的自托管代理的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!