From 84b56527bbe4994af3ea457f0ecb300e1194226b Mon Sep 17 00:00:00 2001 From: Bryan Cook <3217452+bryanbcook@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:12:54 -0400 Subject: [PATCH] use relative path within same context #224 (#225) * use relative path within same context #224 * added tests * updated test case to reflect scoped relative paths. #224 --- .github/workflows/nuget.yml | 1 + src/Sdk/AzurePipelines/AzureDevops.cs | 2 +- .../cross-repo-relative-paths/repo1/pipeline.yml | 9 +++++++++ .../cross-repo-relative-paths/repo2/templates/job.yml | 5 +++++ .../cross-repo-relative-paths/repo2/templates/step.yml | 2 ++ 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 testworkflows/azpipelines/cross-repo-relative-paths/repo1/pipeline.yml create mode 100644 testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/job.yml create mode 100644 testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/step.yml diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index 2c6773bbd63..cd311b2d336 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -173,6 +173,7 @@ jobs: gharun --event azpipelines -C testworkflows/azpipelines/version-literal -W testworkflows/azpipelines/version-literal/pipeline.yml gharun --event azpipelines -C testworkflows/azpipelines/relative-and-absolute-paths -W testworkflows/azpipelines/relative-and-absolute-paths/pipeline.yml gharun --event azpipelines -C testworkflows/azpipelines/null-each-loop -W testworkflows/azpipelines/null-each-loop/pipeline.yml + gharun --event azpipelines -C testworkflows/azpipelines/cross-repo-relative-paths/repo1 -W testworkflows/azpipelines/cross-repo-relative-paths/repo1/pipeline.yml --local-repository central/shared@main=testworkflows/azpipelines/cross-repo-relative-paths/repo2 - name: Windows Container Change Firewall Settings if: contains(matrix.os, 'windows') && !job.container run: | diff --git a/src/Sdk/AzurePipelines/AzureDevops.cs b/src/Sdk/AzurePipelines/AzureDevops.cs index 35d9f1b1c35..a69b8e3071f 100644 --- a/src/Sdk/AzurePipelines/AzureDevops.cs +++ b/src/Sdk/AzurePipelines/AzureDevops.cs @@ -466,7 +466,7 @@ public static MappingToken ReadTemplate(Runner.Server.Azure.Devops.Context conte var fileId = templateContext.GetFileId(filename); // Read the file var finalRepository = afilenameAndRef.Length == 1 ? context.RepositoryAndRef : string.Equals(afilenameAndRef[1], "self", StringComparison.OrdinalIgnoreCase) ? null : context.Repositories.TryGetValue(afilenameAndRef[1], out var ralias) ? ralias : throw new Exception($"Couldn't find repository with alias {afilenameAndRef[1]} in repository resources"); - var finalFileName = afilenameAndRef.Length == 1 ? RelativeTo(context.CWD ?? ".", filename) : filename; + var finalFileName = context.RepositoryAndRef == finalRepository ? RelativeTo(context.CWD ?? ".", filename) : filename; if(finalFileName == null) { throw new Exception($"Couldn't find template location {filenameAndRef}"); } diff --git a/testworkflows/azpipelines/cross-repo-relative-paths/repo1/pipeline.yml b/testworkflows/azpipelines/cross-repo-relative-paths/repo1/pipeline.yml new file mode 100644 index 00000000000..a7096abd889 --- /dev/null +++ b/testworkflows/azpipelines/cross-repo-relative-paths/repo1/pipeline.yml @@ -0,0 +1,9 @@ +resources: + repositories: + - repository: shared + name: central/shared + type: git + ref: main + +jobs: +- template: /templates/job.yml@shared \ No newline at end of file diff --git a/testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/job.yml b/testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/job.yml new file mode 100644 index 00000000000..b6b6439dd84 --- /dev/null +++ b/testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/job.yml @@ -0,0 +1,5 @@ + +jobs: +- job: job1 + steps: + - template: step.yml@shared # scoped relative path \ No newline at end of file diff --git a/testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/step.yml b/testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/step.yml new file mode 100644 index 00000000000..73444cabaea --- /dev/null +++ b/testworkflows/azpipelines/cross-repo-relative-paths/repo2/templates/step.yml @@ -0,0 +1,2 @@ +steps: +- script: exit 0 \ No newline at end of file