

- Username and password
- GitHub app integration
- OpenShift username and password
- SSH key
- Secret file or secret text (key-value pair)
- Certificates (including self-signed certificates)


This script demonstrates a basic pipeline with separate stages for setup and testing.
Method 1: Using Environment Variables for Credentials
To use the credentials in your Pipeline, you can store them as an environment variable. The following example demonstrates how to assign the global credential (“server-creds”) to an environment variable:- The credential string is masked.
- The username is visible in plain text (unless configured as secret).
- The password remains hidden.
Method 2: Using the withCredentials Step
Alternatively, you can use thewithCredentials block to limit the exposure of your credentials. Remove the global environment variable and wrap only the steps that need access to the credential within a withCredentials block. This is particularly useful for username and password credentials.
withCredentials block, you can access the username and password using the variables “myuser” and “mypassword.” For example, you might want to echo these values (keeping in mind that the password will be masked in the logs):
Variables defined within the
withCredentials block are only available within that block. This practice helps keep sensitive information secure by ensuring that credentials are not exposed outside their intended scope.Summary
There are two primary methods for incorporating credentials into your Jenkins Pipeline:- Using environment variables to store the credential.
- Using the
withCredentialsblock to scope access to sensitive data.