0

my set up is as follow I 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://learn.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 :

  1. I like to send in the "run" rest API another parameter that contains the SourceFolder path so that the CopyFiles task will be dynamic and not have hardcode SourceFolder path

  2. 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

UPDATE i 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
}
user63898
  • 29,839
  • 85
  • 272
  • 514

1 Answers1

1

send in the "run" rest API another parameter that contains the SourceFolder path We can use runtime parameters in pipeline.

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}"
        }
}

how do i tell the self-hosted agent to include the directory outside its working dir?

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'"

enter image description here

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 docker running 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://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • Thanks i will try it and report – user63898 Sep 04 '20 at 09:11
  • Hi @user63898, Feel free to let me know if the answer could give you some help. If you still have any questions, I will still be here to help you – Vito Liu Sep 04 '20 at 09:27
  • Thanks im getting error :Unexpected parameter 'Folderpath'" please see my updated question – user63898 Sep 04 '20 at 10:08
  • Hi @user63898, I have updated the answer, please check it. We need to make sure that the parameter folder path is already defined in yaml. – Vito Liu Sep 04 '20 at 10:16
  • Thanks but now im getting this error : [error]Unhandled: Not found SourceFolder: /azp/agent/_work/1/s/{/home/t/copy_dir} as i told you I'm running now the docker self hosted agent and the working dir is /azp – user63898 Sep 04 '20 at 10:37
  • Hi @user63898, Sorry for my mistake, I have update the answer screenshot, we should not add {} in the request body path. The real path on the disc is local path, right? We should add the full path, such as 'E:/agent/_work/1/s' – Vito Liu Sep 07 '20 at 08:04
  • Hi @user63898, does this work now? If you have any concern, feel free to share it here – Vito Liu Sep 08 '20 at 09:33
  • Yes it is working, but the part where i run Fastlane using script failing badly open a new ticket? – user63898 Sep 08 '20 at 11:41
  • thanks for your help , see if you can help here : https://stackoverflow.com/questions/63801672/fastlane-getting-security-seckeychainitemimport-the-specified-keychain-coul – user63898 Sep 08 '20 at 21:16
  • Hi @user63898, You could accept the answer. In this case, others could directly find the useful solution, and my colleague is investigating that ticket, he will help you resolve the issue. Thanks. – Vito Liu Sep 09 '20 at 02:14
  • question, can i ssh directly to the agent somehow to test there the commands? – user63898 Sep 09 '20 at 06:44
  • We can add task and enter the commands, then check the result. – Vito Liu Sep 09 '20 at 09:07