Skip to content

Commit 13b0ab7

Browse files
authored
<Binary/Other>CopyAndPublish.yml: Use bash to parse parameter string (#171)
Uses bash to parse a parameter string that could be empty since it is more robust and consistent than directly depending on pipeline string interpretation logic. This treats the following strings as "empty": - "" - " " Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
1 parent 7615dd3 commit 13b0ab7

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

Steps/BinaryCopyAndPublish.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ parameters:
1717
default: 'Artifacts'
1818

1919
steps:
20+
- bash: |
21+
artifacts_str=$(echo "${{ parameters.artifacts_binary }}" | tr -d '[:space:]')
22+
if [[ -z "$artifacts_str" ]]; then
23+
echo "##vso[task.setvariable variable=artifacts_present]false"
24+
else
25+
echo "##vso[task.setvariable variable=artifacts_present]true"
26+
fi
27+
2028
# Copy binaries to the artifact staging directory
2129
- task: CopyFiles@2
2230
displayName: Copy Build Binaries
@@ -26,7 +34,7 @@ steps:
2634
contents: |
2735
${{ parameters.artifacts_binary }}
2836
flattenFolders: true
29-
condition: and(succeededOrFailed(), ne('${{ parameters.artifacts_binary }}', ''))
37+
condition: and(succeededOrFailed(), eq(variables.artifacts_present, 'true'))
3038

3139
# Publish build artifacts to Azure Artifacts/TFS or a file share
3240
- task: PublishBuildArtifacts@1
@@ -35,4 +43,4 @@ steps:
3543
inputs:
3644
pathtoPublish: "$(Build.ArtifactStagingDirectory)/Binaries"
3745
artifactName: "Binaries ${{ parameters.artifacts_identifier }}"
38-
condition: and(succeededOrFailed(), ne('${{ parameters.artifacts_binary }}', ''))
46+
condition: and(succeededOrFailed(), eq(variables.artifacts_present, 'true'))

Steps/OtherCopyAndPublish.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ parameters:
1717
default: ''
1818

1919
steps:
20+
- bash: |
21+
artifacts_str=$(echo "${{ parameters.artifacts_other }}" | tr -d '[:space:]')
22+
if [[ -z "$artifacts_str" ]]; then
23+
echo "##vso[task.setvariable variable=artifacts_present]false"
24+
else
25+
echo "##vso[task.setvariable variable=artifacts_present]true"
26+
fi
27+
2028
# Copy other files to the artifact staging directory
2129
- task: CopyFiles@2
2230
displayName: Copy Other Files from Build
@@ -26,7 +34,7 @@ steps:
2634
contents: |
2735
${{ parameters.artifacts_other }}
2836
flattenFolders: true
29-
condition: and(succeededOrFailed(), ne('${{ parameters.artifacts_other }}', ''))
37+
condition: and(succeededOrFailed(), eq(variables.artifacts_present, 'true'))
3038

3139
# Publish build artifacts to Azure Artifacts/TFS or a file share
3240
- task: PublishBuildArtifacts@1
@@ -35,4 +43,4 @@ steps:
3543
inputs:
3644
pathtoPublish: "$(Build.ArtifactStagingDirectory)/Other"
3745
artifactName: "Other ${{ parameters.artifacts_identifier }}"
38-
condition: and(succeededOrFailed(), ne('${{ parameters.artifacts_other }}', ''))
46+
condition: and(succeededOrFailed(), eq(variables.artifacts_present, 'true'))

0 commit comments

Comments
 (0)