-
Notifications
You must be signed in to change notification settings - Fork 1
/
veracode-sast-platform-release-candidate-promote-job.yml
146 lines (118 loc) · 6.28 KB
/
veracode-sast-platform-release-candidate-promote-job.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
parameters:
- name: veracodeApiId
displayName: Veracode API ID
default: ""
type: string
- name: veracodeApiKey
displayName: Veracode API Key
default: ""
type: string
- name: applicationName
displayName: Application Name
default: ""
type: string
- name: sandboxName
displayName: Sandbox Name
default: "Release Candidate"
type: string
jobs:
- job: SAST_Release_Candidate_Promote
displayName: Promotion of a Sandbox to Policy
pool:
vmImage: 'ubuntu-latest'
variables:
- name: ApplicationId
- name: SandboxId
- name: AnalysisId
- name: AnalysisName
- name: resultsReady
value: "false"
steps:
- script: java --version
continueOnError: true
displayName: Report Java Version installed
- pwsh: |
$versionstring = curl https://repo1.maven.org/maven2/com/veracode/vosp/api/wrappers/vosp-api-wrappers-java/maven-metadata.xml | Out-String -Stream | Select-String -Pattern 'latest';
$wrapper_version = $versionstring -replace '\s','' -replace '<latest>','' -replace '</latest>','';
echo "Pulling down wrapper version: $wrapper_version"
curl https://repo1.maven.org/maven2/com/veracode/vosp/api/wrappers/vosp-api-wrappers-java/$WRAPPER_VERSION/vosp-api-wrappers-java-$WRAPPER_VERSION-dist.zip -o $(Build.ArtifactStagingDirectory)/dist.zip
7z e $(Build.ArtifactStagingDirectory)/dist.zip -o$(Build.ArtifactStagingDirectory)/extract/ -y
displayName: Downloading the latest version of the Veracode Java API
enabled: true
- script: ls -la $(Build.ArtifactStagingDirectory)
displayName: Show Artifact Directory Content
- script: |
ls -la $(Build.ArtifactStagingDirectory)/extract/
displayName: Show Extract Directory Content
enabled: true
- script: |
java -jar $(Build.ArtifactStagingDirectory)/extract/VeracodeJavaAPI.jar -version
displayName: Veracode Wrapper Version
enabled: false
- pwsh: |
java -jar $(Build.ArtifactStagingDirectory)/extract/VeracodeJavaAPI.jar -vid ${{ parameters.veracodeApiId }} -vkey ${{ parameters.veracodeApiKey }} -action getapplist | Out-File -FilePath applicationlist.xml
[xml]$Xml = Get-Content .\applicationlist.xml
$SnippetNamespace = @{ns = "https://analysiscenter.veracode.com/schema/2.0/applist"}
$app_id = Select-Xml -Xml $Xml -Namespace $SnippetNamespace -XPath "//ns:app[@app_name='${{ parameters.applicationName }}']" | ForEach-Object {$_.Node.app_id}
if($appid -eq ""){
Write-Host Application ${{parameters.applicationName}} not found.
exit 1
}
# Set Output Variable
echo "##vso[task.setvariable variable=ApplicationId]$app_id"
echo "Application ID: $$app_id"
displayName: Retrieving Application ID
- pwsh: |
Write-Host "Application ID: $(ApplicationId)"
java -jar $(Build.ArtifactStagingDirectory)/extract/VeracodeJavaAPI.jar -vid ${{ parameters.veracodeApiId }} -vkey ${{ parameters.veracodeApiKey }} -action getsandboxlist -appid $(ApplicationId) | Out-File -FilePath sandboxlist.xml
[xml]$Xml = Get-Content .\sandboxlist.xml
$SnippetNamespace = @{ns = "https://analysiscenter.veracode.com/schema/4.0/sandboxlist"}
# ${{parameters.sandboxName}}
$sandbox_id = Select-Xml -Xml $Xml -Namespace $SnippetNamespace -XPath "//ns:sandbox[@sandbox_name='${{ parameters.sandboxName }}']" | ForEach-Object {$_.Node.sandbox_id}
if($sandbox_id -eq ""){
Write-Host Sandbox ${{ parameters.sandboxName }} not found.
exit 1
}
# Set Output Variable
echo "##vso[task.setvariable variable=SandboxId]$sandbox_id"
Write-Host "Sandbox ID: $sandbox_id"
displayName: Retrieving Sandbox ID
- pwsh: |
Write-Host "Sandbox ID: $(SandboxId)"
java -jar $(Build.ArtifactStagingDirectory)/extract/VeracodeJavaAPI.jar -vid ${{ parameters.veracodeApiId }} -vkey ${{ parameters.veracodeApiKey }} -action GetBuildList -appid $(ApplicationId) -sandboxid $(SandboxId) | Out-File -FilePath buildlist.xml
[xml]$Xml = Get-Content .\buildlist.xml
$SnippetNamespace = @{ns = "https://analysiscenter.veracode.com/schema/2.0/buildlist"}
$Build = Select-Xml -Xml $Xml -Namespace $SnippetNamespace -XPath "//ns:build[last()]"
$BuildId = $Build.Node.build_id
$Version = $Build.Node.version
if($BuildId -eq ""){
Write-Host "No analyses found within sandbox $(SandboxId)"
exit 1
}
echo "Analysis ID: $BuildId"
echo "Analysis Name: $Version"
# Set Output Variables
echo "##vso[task.setvariable variable=AnalysisName]$Version"
echo "##vso[task.setvariable variable=AnalysisId]$BuildId"
displayName: Retrieving Analysis List
- pwsh: |
Write-Host "Analysis ID: $(AnalysisId)"
java -jar $(Build.ArtifactStagingDirectory)/extract/VeracodeJavaAPI.jar -vid ${{ parameters.veracodeApiId }} -vkey ${{ parameters.veracodeApiKey }} -action GetBuildInfo -appid $(ApplicationId) -sandboxid $(SandboxId) -buildid $(AnalysisId) | Out-File -FilePath buildinfo.xml
[xml]$Xml = Get-Content .\buildinfo.xml
$SnippetNamespace = @{ns = "https://analysiscenter.veracode.com/schema/4.0/buildinfo"}
$element = Select-Xml -Xml $Xml -Namespace $SnippetNamespace -XPath "//ns:build"
$results_ready = $element.Node.results_ready
echo "Result Ready: $results_ready"
# Set Output Variables
echo "##vso[task.setvariable variable=resultsReady]$results_ready"
if($results_ready -eq 'false'){
Write-Host Sandbox Analysis $(AnalysisName) is not in a ready state to be promoted.
exit 1
}
displayName: Evaluating Analysis State
enabled: true
- pwsh: |
Write-Host "Promoting: $(AnalysisName) to Policy Level"
java -jar $(Build.ArtifactStagingDirectory)/extract/VeracodeJavaAPI.jar -vid ${{ parameters.veracodeApiId }} -vkey ${{ parameters.veracodeApiKey }} -action PromoteSandbox -buildid $(AnalysisId)
condition: eq(variables['resultsReady'],'true')
displayName: Promoting Scan