CredentialsPlugin.md
May 18, 2022 ยท View on GitHub
CredentialsPlugin
Enable this plugin to inject credentials into your stages using the Jenkins Credentials Plugin.
One-time setup:
- Install the Jenkins Credentials Binding Plugin on your Jenkins server.
- Define a credential that you want to inject.
Add any number of credentials bindings that you want to wrap your stages, with withBinding. Each call to this method will cumulatively add more credentials. See the Credentials Binding Plugin homepage for the list of supported bindings.
// Jenkinsfile
@Library(['terraform-pipeline@v5.0']) _
Jenkinsfile.init(this)
// Add credentials to all Stages from usernamePassword, usernameColonPassword, and string credentials
CredentialsPlugin.withBinding { usernamePassword(credentialsId: 'my-user-pass', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD') }
.withBinding { usernameColonPassword(credentialsId: 'my-user-colon-pass', variable: 'USERPASS') }
.withBinding { string(credentialsId: 'my-string-token', variable: 'TOKEN') }
.init()
def validate = new TerraformValidateStage()
def build = new BuildStage()
def deployQa = new TerraformEnvironmentStage('qa')
def testQa = new RegressionStage()
def deployUat = new TerraformEnvironmentStage('uat')
def deployProd = new TerraformEnvironmentStage('prod')
validate.then(build)
.then(deployQa)
.then(testQa)
.then(deployUat)
.then(deployProd)
.build()