This bash script intelligently analyzes artifact storage folders and collects Java and .NET compiled applications while handling 3rd party libraries and excluding test artifacts. It's designed for use in CI/CD pipelines, build systems, and general artifact management scenarios.
Ready-to-use CI/CD pipeline examples are included for:
- Azure DevOps:
azure-pipeline-example.yml- Complete pipeline with artifact collection and Veracode scanning - GitHub Actions:
github-actions-example.yml- Full workflow using the official Veracode GitHub Action - GitLab CI:
gitlab-ci-example.yml- Complete GitLab CI pipeline with Veracode integration
- Smart Artifact Detection: Automatically identifies compiled Java applications (.jar, .war, .ear) and .NET applications (.dll, .exe, .nupkg)
- 3rd Party Library Handling: Intelligently determines if 3rd party libraries are already included in compiled artifacts
- Test Artifact Filtering: Automatically excludes unit test artifacts
- Archive Validation: Validates that files are proper Java archives or .NET assemblies before processing
- Comprehensive Logging: Multiple verbosity levels with colored output for easy debugging
- Flexible Output: Configurable output directory with detailed collection summary
- Bash: Version 4.0 or higher (for associative arrays and advanced features)
- unzip: For archive validation and content analysis
- stat: For file size checking (usually available on most systems)
- Download the script to your system
- Make it executable:
chmod +x collect_veracode_artifacts.sh
./collect_veracode_artifacts.sh /path/to/artifacts# Enable debug output
./collect_veracode_artifacts.sh -d /path/to/artifacts
# Enable verbose output
./collect_veracode_artifacts.sh -v /path/to/artifacts
# Specify custom output directory
./collect_veracode_artifacts.sh -o /custom/output /path/to/artifacts
# Combine options
./collect_veracode_artifacts.sh -d -v -o /custom/output /path/to/artifacts| Option | Long Option | Description |
|---|---|---|
-d |
--debug |
Enable debug output |
-v |
--verbose |
Enable verbose output |
-h |
--help |
Show help message |
-o |
--output |
Specify output folder (default: ./collected_artifacts) |
| Variable | Description | Default |
|---|---|---|
DEBUG |
Enable debug mode | false |
VERBOSE |
Enable verbose mode | false |
The script starts by scanning the specified artifact folder for:
.jarfiles (Java Archive).warfiles (Web Application Archive).earfiles (Enterprise Application Archive).dllfiles (.NET Dynamic Link Library).exefiles (.NET Executable).nupkgfiles (.NET NuGet Package)
Each found file is validated to ensure it's a proper Java archive or .NET assembly:
- File existence and readability checks
- File size validation (skips empty files)
- Archive structure validation using
unzip -tfor Java archives - Assembly validation for .NET files
JAR files are analyzed to identify test artifacts:
- Filename pattern matching (contains "test", "Test", "TEST")
- Content analysis for test-related classes and dependencies
- Manifest file inspection for test indicators
JAR files are examined to determine if they contain 3rd party libraries:
- META-INF structure analysis
- Package name pattern matching
- Dependency information detection
The script follows this collection strategy:
- Priority 1: Collect compiled applications (.jar, .war, .ear, .dll, .exe, .nupkg)
- Graceful Exit: If no compiled apps found, finish gracefully without collecting 3rd party libraries
- Always Skip: Test artifacts and invalid archives
- Copies selected artifacts to the output directory
- Creates a detailed collection summary (
collection_summary.txt) - Provides comprehensive logging throughout the process
./collect_veracode_artifacts.sh /tmp/build-artifactsThis will analyze /tmp/build-artifacts and collect artifacts to ./collected_artifacts/.
./collect_veracode_artifacts.sh -d -o /tmp/collected /tmp/build-artifactsThis enables debug output and saves collected artifacts to /tmp/collected/.
DEBUG=true VERBOSE=true ./collect_veracode_artifacts.sh /tmp/build-artifactsThis enables both debug and verbose modes via environment variables.
collected_artifacts/
├── application.jar # Compiled Java application
├── webapp.war # Java web application
├── enterprise.ear # Java enterprise application
├── app.dll # .NET assembly
├── console.exe # .NET executable
├── package.nupkg # .NET NuGet package
└── collection_summary.txt # Detailed collection report
The script generates a collection_summary.txt file containing:
- Timestamp of collection
- Source folder path
- Count of collected artifacts by type
- List of all collected files
- Count of skipped test artifacts
- Count of invalid archives found
When debug mode is enabled (-d or DEBUG=true), the script provides detailed information about:
- File validation steps
- Archive content analysis
- Decision-making process for each file
- Internal state and variable values
When verbose mode is enabled (-v or VERBOSE=true), the script shows:
- All discovered files
- Detailed processing steps
- File analysis results
The script includes comprehensive error handling:
- Graceful failure for missing dependencies
- Detailed error messages for invalid inputs
- Safe handling of corrupted or invalid archives
- Proper cleanup of temporary files
This script is designed to work seamlessly with major CI/CD platforms. Complete pipeline examples are provided for each platform:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
./collect_veracode_artifacts.sh -d -v $(Build.ArtifactStagingDirectory)Complete example: See azure-pipeline-example.yml for a full pipeline that collects artifacts and runs Veracode scans.
- name: Collect Artifacts
run: ./collect_veracode_artifacts.sh -d -v ${{ github.workspace }}/buildComplete example: See github-actions-example.yml for a full workflow that integrates with the Veracode GitHub Action.
- script: ./collect_veracode_artifacts.sh -d -v $CI_PROJECT_DIR/buildComplete example: See gitlab-ci-example.yml for a complete GitLab CI pipeline with artifact collection and Veracode integration.
#!/bin/bash
# Collect artifacts after Maven build
./collect_veracode_artifacts.sh -d -o "$WORKSPACE/artifacts" "$BUILD_DIR/target"
# Collect artifacts after .NET build
./collect_veracode_artifacts.sh -d -o "$WORKSPACE/artifacts" "$BUILD_DIR/bin"# Analyze a specific build output
./collect_veracode_artifacts.sh -v /path/to/build/output
# Analyze deployment artifacts
./collect_veracode_artifacts.sh -v /path/to/deployment/folder- Permission Denied: Ensure the script is executable (
chmod +x) - unzip not found: Install unzip package for your system
- Empty output: Check if the artifact folder contains valid Java archives
- Test artifacts collected: Verify the test detection logic meets your needs
- Use
-dflag to see detailed decision-making process - Use
-vflag to see all discovered files - Check the collection summary for detailed results
- Verify file permissions and accessibility
Feel free to submit issues, feature requests, or pull requests to improve the script.
This script is provided as-is for educational and operational purposes.