Currently I'm facing problem with attemps to read dotenv variables in jenkinsfile. In test framework we're using, we do store some environment variables under .env file, which is based on dotenv npm package. This .env file is a part of our code repository.
Those env variables are just like
A = "value1"
B = "value2"
Based on scenario result I'm trying to set "FAILURE" value to one of these .env variables, that I'd like to read within Jenkinsfile.
After( async function (scenario) {
const result = scenario.result.status;
if (result === "failed") {
process.env.SCENARIO_RESULT = "FAILURE"
});
Then in Jenkinsfile I'm trying to reach this .env variable, like this
properties([......
buildDiscarder(
logRotator( .... ))])
SCENARIO_RESULT = '' *//here declaring initial value*
podTemplate( ... ) {
timestamps { ....
container ( .....
stage('cleaning workspace') {...}
stage('clone repo') {...}
stage('run tests') {
try {
if(SCENARIO_RESULT == 'FAILURE'){
currentBuild.result = 'FAILURE'
}
}
It doesn't realy work though, I was just declaring this variable at the top of jenkins file, assigning some start value to it, but still it doesn't gets updated.
Is there a way that I could pass this .env variables value to jenkinsfile variable?