🔐 Environment & Credentials
Environment & Credentials: A Jenkins `environment` block is like a sealed envelope handed to a courier: the courier (the pipeline) can use what's inside — a password, an API toke
A Jenkins `environment` block is like a sealed envelope handed to a courier: the courier (the pipeline) can use what's inside — a password, an API token — to complete the delivery, but they can never open the envelope and read the contents out loud, because Jenkins automatically masks any credential value the moment it would appear in a console log. The thought-provoking question: if `sh 'echo $DB_CREDS_PSW'` would just print the password in plaintext to the log, doesn't the whole masking mechanism fall apart with one careless line? Not quite — Jenkins scans the raw output BEFORE it's written to the log and replaces any substring matching a known credential value with ****, which is exactly why you should never manually construct a secret from fragments. Java analogy: this is the same discipline as never logging a raw `Exception` that might contain a `getMessage()` with an embedded password — the masking has to happen at the sink (the log itself), not by trusting every caller to remember not to print it. In real QA work, a leaked database credential in a public Jenkins console log — visible to anyone with read access to the job — has caused real production incidents; the `credentials()` binding exists specifically so a QA automation engineer writing a Jenkinsfile never has to paste a raw password into version-controlled code in the first place.
Environment Variables
Using variables and credentials in Jenkinsfile
Micro Lab: Jenkinsfile pipeline stage completion
Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.
Step by Step: Jenkinsfile pipeline stage completion
Choose execution place with pipeline and agent
Fetch source code with checkout
Run the build/dependency stage
Produce evidence in the test stage
Publish reports and notifications inside post always
Order the Jenkinsfile quality-gate flow.
Conditional Stages (when directive)
Only deploy on main branch, require approval for prod