Jenkins CI/CD Environment includes automated security scanning that detects hardcoded credentials before code is deployed. The Security Scan - Password Detection stage inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/infra-neo/CICD/llms.txt
Use this file to discover all available pages before exploring further.
Jenkinsfile.enhanced runs grep-based pattern matching against all source files under the src/ directory and fails the build immediately if any matches are found — preventing secrets from ever reaching a deployed artifact.
How It Works
The scan stage runs three independent grep passes againstsrc/, each targeting a different category of hardcoded secret. Results are appended to a security-scan.txt report file that is archived alongside build artifacts at the end of the run.
| Pattern | What it catches |
|---|---|
grep -r -n -i "password.*=.*['\"]" | Hardcoded passwords in any assignment where the right-hand side begins with a quote character |
grep -r -n -i "api[_-]key.*=.*['\"]" | Hardcoded API keys following the api_key or api-key naming convention |
grep -r -n -i "token.*=.*['\"]" | Hardcoded tokens such as bearer tokens, personal access tokens, or session tokens |
password.*=.*['\"][^$] — is used to decide whether to abort the pipeline. The [^$] suffix excludes values that begin with $, which are environment variable references and are safe.
Patterns That Fail the Build
Any Java source file (or file in any language undersrc/) that contains assignments matching the above patterns will cause the Security Scan stage to exit with a non-zero status, aborting the pipeline and marking the build as FAILED.
Correct Usage
Replace every hardcoded literal secret with a call toSystem.getenv() or an equivalent environment-variable lookup for your framework:
$, properties-file references that use the ${VAR} syntax are also safe:
Configuring Scan Behavior
Thesecurity block in build-config.yml controls three scan-related behaviors:
| Key | Type | Effect |
|---|---|---|
security.password_scan | boolean | When true, the Security Scan stage is active and will fail the build on detection |
security.mask_credentials | boolean | When true, credential values passed via withCredentials() are replaced with **** in all build log output |
security.enforce_env_vars | boolean | When true, the pipeline enforces that secrets are sourced from environment variables rather than embedded in configuration files |
Credential Masking
Whensecurity.mask_credentials: true is set, any secret bound through a Jenkins withCredentials() block is automatically masked in build logs. Jenkins replaces the literal value with **** wherever it would appear in standard output or standard error.
mask_credentials setting in build-config.yml.
Managing Secrets
Copy the secrets template
Add real values to secrets.env
Open
config/secrets.env in your editor and replace placeholder values with real credentials. This file must never be committed to version control.Store sensitive values as Jenkins Credentials
In Jenkins navigate to Manage Jenkins → Credentials → System → Global credentials and add each secret:
- Use Username with password for service accounts (Nexus, WildFly, JBoss)
- Use Secret text for API tokens and single-value secrets
- Assign a memorable
credentialsIdthat matches what the Jenkinsfile expects
For additional security hardening including enabling HTTPS on Jenkins and isolating services with Docker network policies, see the Configuration Guide.
