Skip to content

Commit 4464d2b

Browse files
authored
add dependency track to build pipeline
1 parent b3be12d commit 4464d2b

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

azure-pipelines.yml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ stages:
3333
NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages
3434
jobs:
3535
- job: Build
36-
pool:
36+
variables:
37+
- group: "dependency-track"
38+
pool:
3739
vmImage: ubuntu-latest
3840
steps:
3941
# Checkout source (avoid shallow clone to calculate version height)
@@ -104,3 +106,70 @@ stages:
104106
inputs:
105107
targetPath: $(Build.SourcesDirectory)/src
106108
artifactName: build_output
109+
110+
# Generate/upload SBOM with cdxgen
111+
- script: |
112+
cd $(Build.SourcesDirectory)
113+
npm install --global @cyclonedx/cdxgen
114+
displayName: 'Install cdxgen'
115+
116+
- task: PowerShell@2
117+
displayName: 'Generate & upload SBOM with cdxgen (pwsh)'
118+
inputs:
119+
targetType: 'inline'
120+
pwsh: true
121+
script: |
122+
mkdir -Force "$(Build.ArtifactStagingDirectory)/bom"
123+
Set-Location "$(Build.SourcesDirectory)"
124+
125+
# version
126+
$VERSION = 'vUNKNOWN'
127+
if (Test-Path 'version.json') {
128+
try {
129+
$rawVersion = (Get-Content 'version.json' -Raw | ConvertFrom-Json).version
130+
} catch {
131+
if ((Get-Content 'version.json' -Raw) -match '"version"\s*:\s*"([^"]+)"') {
132+
$rawVersion = $matches[1]
133+
}
134+
}
135+
136+
if ($rawVersion) {
137+
# Extract major part (e.g. "1" from "1.2.3") and add "v" prefix
138+
if ($rawVersion -match '^(\d+)\.') {
139+
$VERSION = "v$($matches[1])"
140+
} elseif ($rawVersion -match '^\d+$') {
141+
$VERSION = "v$rawVersion"
142+
} else {
143+
$VERSION = "vUNKNOWN"
144+
}
145+
}
146+
}
147+
148+
Write-Host "Project version: $VERSION"
149+
150+
# derive project name
151+
$PROJECT_NAME = [System.IO.Path]::GetFileNameWithoutExtension("$(solution)")
152+
Write-Host "Project name: $PROJECT_NAME"
153+
154+
# short debug (last 5 chars)
155+
foreach ($name in 'DT_BASE_URL','DT_API_KEY') {
156+
$v = (Get-Item "Env:$name").Value
157+
if ($v) {
158+
$last = if ($v.Length -gt 5) { $v.Substring($v.Length-5) } else { $v }
159+
Write-Host "$name (last5): ...$last"
160+
} else {
161+
Write-Host "$name is empty"
162+
}
163+
}
164+
165+
Write-Host 'Running cdxgen ...'
166+
& cdxgen '--recurse' '--output' "$(Build.ArtifactStagingDirectory)/bom/bom.json" '--json-pretty' '--project-group' 'DXP' '--project-name' $PROJECT_NAME '--project-version' $VERSION '--server-url' $env:DT_BASE_URL '--api-key' $env:DT_API_KEY
167+
env:
168+
DT_API_KEY: $(DT_API_KEY)
169+
DT_BASE_URL: $(DT_BASE_URL)
170+
171+
- task: PublishPipelineArtifact@1
172+
displayName: 'Publish SBOM Artifact'
173+
inputs:
174+
targetPath: $(Build.ArtifactStagingDirectory)/bom
175+
artifactName: SBOM

0 commit comments

Comments
 (0)