Score:0

Environment variables in Jenkinsfile

tn flag

I have a github project with my Jenkinsfile used for deployment, actually managing only the dev environment.

I'd like to manage the production environment as well, and some parameters would differ from dev to production.

Is it possible to manage this through the same Jenkinsfile, or do I need to create a separate Jenkinsfile to manage the prod settings in it ?

Score:0
se flag

You can use environment specific variables in one Jenkinsfile with Declarative Pipeline. If you configured your Jenkins pipeline to accept parameters using the Build with Parameters option, those parameters are accessible as members of the params variable.

Assuming that a String parameter named "DEPLOY_TO" has been configuring in the Jenkinsfile, it can access that parameter via ${params.DEPLOY_TO}:

 environment {
    ...
    DEPLOY_ENV = "${params.DEPLOY_TO}"
    ...
}

You can differ this variable between your environments while creating that environment's build job with the same Jenkinsfile.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.