parameters:
  artifactName: ''
  targetPath: ''
  displayName: ''

steps:
- script: |
    set -e
    ARTIFACT_NAME="${{ parameters.artifactName }}-$(Build.BuildId)-$(System.StageAttempt)-$(System.PhaseAttempt)-$(Agent.OS)-$(Agent.OSArchitecture)"

    echo "Artifact name: '${ARTIFACT_NAME}'"
    echo "##vso[task.setvariable variable=${{ parameters.artifactName }};isOutput=true]${ARTIFACT_NAME}"
  name: artifacts_${{ parameters.artifactName }}
  displayName: Generate unique artifact name for ${{ parameters.artifactName }}

- task: PublishPipelineArtifact@1
  inputs:
    artifactName: $(artifacts_${{ parameters.artifactName }}.${{ parameters.artifactName }})
    targetPath: ${{ parameters.targetPath }}
  displayName: ${{ parameters.displayName }}
