Skip to content

Commit be443f8

Browse files
authored
SP-2933_dependency-track
* Added dependency track integration * Upgraded scanoss-py version to v1.40.1
2 parents 787ea14 + a159d7b commit be443f8

14 files changed

Lines changed: 1186 additions & 26 deletions

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Changes...
1111

12+
## [1.2.0] - 2025-11-7
13+
### Added
14+
- Added dependency track integration
15+
### Changed
16+
- Upgraded scanoss-py version to v1.40.1
17+
1218
## [1.1.0] - 2025-10-22
1319
### Added
1420
- Added raw results conversion to CycloneDX, SPDXLite and CSV
1521
### Changed
1622
- Upgraded scanoss-py version to v1.37.1
1723

18-
[1.1.0]: https://github.com/scanoss/ado-code-scan/compare/v1.0.3...v1.1.0
24+
[1.1.0]: https://github.com/scanoss/ado-code-scan/compare/v1.0.3...v1.1.0
25+
[1.2.0]: https://github.com/scanoss/ado-code-scan/compare/v1.1.0...v1.2.0

OVERVIEW.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ When the pipeline is manually triggered or runs on a schedule, the results are u
149149
| dependenciesScope | Gets development or production dependencies (scopes: dev - prod ) | Optional | - |
150150
| dependenciesScopeInclude | Custom list of dependency scopes to be included. Provide scopes as a comma-separated list. | Optional | - |
151151
| dependenciesScopeExclude | Custom list of dependency scopes to be excluded. Provide scopes as a comma-separated list. | Optional | - |
152-
| policies | List of policies separated by commas, options available are: copyleft, undeclared. | Optional | - |
152+
| policies | List of policies separated by commas, options available are: copyleft, undeclared, deptrack. | Optional | - |
153153
| policiesHaltOnFailure | Halt check on policy failure. If set to false checks will not fail. | Optional | `true` |
154+
| depTrackEnabled | Enable or disable Dependency Track SBOM upload and status reporting. | Optional | `false` |
155+
| depTrackUrl | Dependency Track server URL (e.g., https://deptrack.example.com). | Optional | - |
156+
| depTrackApikey | Dependency Track API key for authentication. | Optional | - |
157+
| depTrackProjectId | UUID of an existing Dependency Track project (alternative to name/version). | Optional | - |
158+
| depTrackProjectName | Dependency Track project name (required if projectId not provided). | Optional | - |
159+
| depTrackProjectVersion | Dependency Track project version (required if projectId not provided). | Optional | - |
154160
| apiUrl | SCANOSS API URL | Optional | `https://api.osskb.org/scan/direct` |
155161
| apiKey | SCANOSS API Key | Optional | - |
156162
| runtimeContainer | Runtime URL | Optional | `ghcr.io/scanoss/scanoss-py:v1.37.1` |
@@ -164,21 +170,73 @@ When the pipeline is manually triggered or runs on a schedule, the results are u
164170
| debug | Enable debugging | Optional | `false` |
165171

166172
## Policy Checks
167-
The SCANOSS Code Scan Task includes two configurable policies:
173+
The SCANOSS Code Scan Task includes three configurable policies:
168174

169-
1. Copyleft: This policy checks if any component or code snippet is associated with a copyleft license. If such a
175+
1. **Copyleft**: This policy checks if any component or code snippet is associated with a copyleft license. If such a
170176
license is detected, the pull request (PR) is rejected. The default list of Copyleft licenses is defined in the following [file](https://github.com/scanoss/ado-code-scan/blob/1218c4fe2dcda5f807b505e271096b1ec0afd8a9/codescantask/utils/license.utils.ts#L4).
171177

172-
2. Undeclared: This policy compares the components detected in the repository against those declared in the scanoss.json
178+
2. **Undeclared**: This policy compares the components detected in the repository against those declared in the scanoss.json
173179
file. If there are undeclared components, the PR is rejected.
174180

181+
3. **Dependency Track** (deptrack): This policy integrates with a Dependency Track server to check for policy violations including security vulnerabilities, license violations, and compliance issues as configured in your Dependency Track policies. The policy check queries an existing Dependency Track project for violations and reports them in the pipeline.
182+
183+
**Requirements:**
184+
- Dependency Track server URL and API key
185+
- Either a project UUID or project name/version
186+
- The policy runs even if SBOM upload is disabled, but will show warnings if checking against potentially stale data
187+
188+
**Configuration Example:**
189+
```yaml
190+
inputs:
191+
policies: copyleft,undeclared,deptrack
192+
depTrackEnabled: true
193+
depTrackUrl: 'https://deptrack.example.com'
194+
depTrackApikey: $(DEPTRACK_API_KEY)
195+
depTrackProjectName: 'my-project'
196+
depTrackProjectVersion: '1.0.0'
197+
```
198+
175199
Additionally, if it is a Pull Request, a comment with a summary of the report will be automatically generated.
176200

177201
![Comments on PR Undeclared Components](https://github.com/scanoss/integration-azure-DevOps/blob/main/.github/assets/pr_comment_undeclared_components.png?raw=true)
178202

179203

180204
![Comments on PR Copyleft licenses](https://github.com/scanoss/integration-azure-DevOps/blob/main/.github/assets/pr_comment_copyleft.png?raw=true)
181205

206+
## Dependency Track Integration
207+
208+
The SCANOSS Code Scan Task integrates with Dependency Track to provide enhanced vulnerability tracking and policy enforcement. This integration consists of two main features:
209+
210+
### 1. SBOM Upload Status Check
211+
212+
When `depTrackEnabled` is set to `true`, the task will automatically upload a CycloneDX SBOM to your Dependency Track server and report the upload status as a separate PR status check. This status check provides:
213+
214+
- **Success/Failure status**: Visual indicator of whether the SBOM was successfully uploaded
215+
- **Upload details**: Information about the uploaded SBOM including:
216+
- Project name and version
217+
- Number of components analyzed
218+
- File size and upload time
219+
- Direct link to the project in Dependency Track
220+
- **PR comments**: Detailed success or failure messages posted as PR comments
221+
- **Troubleshooting guidance**: If upload fails, helpful error messages with configuration tips
222+
223+
**Note**: The SBOM upload status check runs independently from the policy checks. You can enable SBOM upload without enabling the Dependency Track policy check.
224+
225+
**Configuration Example:**
226+
```yaml
227+
inputs:
228+
depTrackEnabled: true
229+
depTrackUrl: 'https://deptrack.example.com'
230+
depTrackApikey: $(DEPTRACK_API_KEY)
231+
depTrackProjectName: 'my-project'
232+
depTrackProjectVersion: '1.0.0'
233+
```
234+
235+
### 2. Dependency Track Policy Check
236+
237+
The Dependency Track policy check (enabled by adding `deptrack` to the `policies` parameter) queries your Dependency Track server for policy violations and fails the build if violations are found. This is separate from the upload functionality and can be used independently.
238+
239+
See the **Policy Checks** section above for detailed information about the Dependency Track policy check.
182240

183241
## Artifacts
184242
The scan results and policy check outcomes are uploaded to the artifacts folder of the specific run of the pipeline.

codescantask/app.input.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,33 @@ export const API_URL = tl.getInput('apiUrl');
3434
export const OUTPUT_FILEPATH = tl.getInput('outputFilepath') || "scanoss-raw.json";
3535
export const REPO_DIR = tl.getVariable('Build.Repository.LocalPath') || ''; // Get repository path
3636
export const POLICIES_HALT_ON_FAILURE = tl.getInput('policiesHaltOnFailure') === 'true';
37-
export const RUNTIME_CONTAINER = tl.getInput('runtimeContainer') || "ghcr.io/scanoss/scanoss-py:v1.37.1";
37+
export const RUNTIME_CONTAINER = tl.getInput('runtimeContainer') || "ghcr.io/scanoss/scanoss-py:v1.40.1";
3838
export const SKIP_SNIPPETS = tl.getInput('skipSnippets') === 'true';
3939
export const SCAN_FILES = tl.getInput('scanFiles') === 'true';
4040
export const SCANOSS_SETTINGS = tl.getInput('scanossSettings') === 'true';
4141
export const SETTINGS_FILE_PATH = tl.getInput('settingsFilepath') || 'scanoss.json';
4242
export const EXECUTABLE = 'docker';
43-
export const DEBUG = tl.getInput('debug') === 'true';
43+
export const DEBUG = tl.getInput('debug') === 'true';
44+
45+
// ============================================================================
46+
// Dependency Track Configuration
47+
// ============================================================================
48+
export const DEPENDENCY_TRACK_ENABLED = tl.getInput('depTrackEnabled') === 'true';
49+
export const DEPENDENCY_TRACK_URL = tl.getInput('depTrackUrl');
50+
export const DEPENDENCY_TRACK_API_KEY = tl.getInput('depTrackApikey');
51+
/**
52+
* UUID of an existing project in Dependency Track.
53+
* Used for uploading to a specific project. Optional if project name/version provided.
54+
*/
55+
export let DEPENDENCY_TRACK_PROJECT_ID = tl.getInput('depTrackProjectId');
56+
export const DEPENDENCY_TRACK_PROJECT_NAME = tl.getInput('depTrackProjectName');
57+
export const DEPENDENCY_TRACK_PROJECT_VERSION = tl.getInput('depTrackProjectVersion');
58+
59+
export let DEPENDENCY_TRACK_UPLOAD_TOKEN: string | undefined;
60+
61+
export const setDependencyTrackUploadToken = (token: string) => {
62+
DEPENDENCY_TRACK_UPLOAD_TOKEN = token;
63+
};
64+
export const setDependencyTrackProjectId = (id: string) => {
65+
DEPENDENCY_TRACK_PROJECT_ID = id;
66+
};

codescantask/index.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import tl = require('azure-pipelines-task-lib/task');
2525
import { ScanService } from './services/scan.service';
2626
import { scanossService } from "./services/scanoss.service";
2727
import { policyManager } from './policies/policy.manager';
28+
import { DependencyTrackService } from './services/dependency-track.service';
29+
import { DependencyTrackStatusService } from './services/dependency-track-status.service';
30+
import { DepTrackPolicyCheck } from './policies/dep-track-policy-check';
31+
import {DEPENDENCY_TRACK_ENABLED, setDependencyTrackProjectId, setDependencyTrackUploadToken} from "./app.input";
32+
2833
async function run() {
2934
try {
3035
console.log("Starting scan");
@@ -38,18 +43,36 @@ async function run() {
3843
await scanossService.reformatScanResults(format);
3944
}
4045

41-
// run policies
46+
// Dependency Track Upload
47+
let uploadAttempted = false;
48+
if (DEPENDENCY_TRACK_ENABLED) {
49+
const dtService = new DependencyTrackService();
50+
const uploadResult = await dtService.uploadToDependencyTrack();
51+
const dtStatusService = new DependencyTrackStatusService();
52+
await dtStatusService.reportUploadStatus(uploadResult);
53+
// Set flag for policy check to know upload was attempted
54+
uploadAttempted = uploadResult.enabled;
55+
if (uploadResult.success && uploadResult.uploadToken && uploadResult.projectId) {
56+
// Store upload token and project ID for policy check
57+
setDependencyTrackUploadToken(uploadResult.uploadToken);
58+
setDependencyTrackProjectId(uploadResult.projectId);
59+
}
60+
}
61+
62+
// Run policies
4263
for (const policy of policies) {
64+
// If this is a Dependency Track policy, set the upload attempted flag
65+
if (policy instanceof DepTrackPolicyCheck) {
66+
policy.setUploadAttempted(uploadAttempted);
67+
}
4368
await policy.run();
4469
}
4570

46-
}
47-
catch (err:any) {
71+
} catch (err:any) {
4872
tl.setResult(tl.TaskResult.Failed, err.message);
4973
}
5074
}
51-
52-
53-
54-
55-
run();
75+
run().catch((err) => {
76+
tl.setResult(tl.TaskResult.Failed, err.message || 'Unknown error occurred');
77+
process.exit(1);
78+
});

codescantask/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codescantask/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-devops-integration",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)