pipeline blockenvironment block to bind credentials with credentials()pipeline blockenvironment block to bind credentials with credentials()pipeline {} and inside it add an empty agent any block.Start with the pipeline block and specify agent any to run on any available agent.
pipeline block, add an environment block that binds the Jenkins credential with ID my-credentials to environment variables USERNAME and PASSWORD using credentials('my-credentials').Note: Jenkins declarative pipeline does not support accessing username and password separately using credentials(). Instead, use the usernamePassword credentials binding in a withCredentials block inside steps. The environment block can only bind a single string credential using credentials('id').
For username/password pairs, use withCredentials([usernamePassword(credentialsId: 'my-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { ... } inside steps.
pipeline block, add a stages block with one stage named 'Print Credentials'. Inside the stage, add a steps block with a sh command that prints $USERNAME and $PASSWORD environment variables.Use withCredentials inside steps to bind username and password credentials to environment variables.
my-credentials. Write a sh command that prints Username: $USERNAME and Password: $PASSWORD.When you run the pipeline, Jenkins replaces $USERNAME and $PASSWORD with the actual credential values.