generate-sbom-prep.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. source="${BASH_SOURCE[0]}"
  3. # resolve $SOURCE until the file is no longer a symlink
  4. while [[ -h $source ]]; do
  5. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  6. source="$(readlink "$source")"
  7. # if $source was a relative symlink, we need to resolve it relative to the path where the
  8. # symlink file was located
  9. [[ $source != /* ]] && source="$scriptroot/$source"
  10. done
  11. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  12. . $scriptroot/pipeline-logging-functions.sh
  13. manifest_dir=$1
  14. if [ ! -d "$manifest_dir" ] ; then
  15. mkdir -p "$manifest_dir"
  16. echo "Sbom directory created." $manifest_dir
  17. else
  18. Write-PipelineTelemetryError -category 'Build' "Unable to create sbom folder."
  19. fi
  20. artifact_name=$SYSTEM_STAGENAME"_"$AGENT_JOBNAME"_SBOM"
  21. echo "Artifact name before : "$artifact_name
  22. # replace all special characters with _, some builds use special characters like : in Agent.Jobname, that is not a permissible name while uploading artifacts.
  23. safe_artifact_name="${artifact_name//["/:<>\\|?@*$" ]/_}"
  24. echo "Artifact name after : "$safe_artifact_name
  25. export ARTIFACT_NAME=$safe_artifact_name
  26. echo "##vso[task.setvariable variable=ARTIFACT_NAME]$safe_artifact_name"
  27. exit 0