Not able to get the value of jenkins environment variable in otherfile

Hi All,

I am trying to create access token for Jfrog with the help of terraform script in jenkins job, After generating the token I’m accessing it to a env variable TOKEN_VALUE, I have to update the new value in a variable access_token in file variable.tf, but not able to update, I am able to echo “TOKEN_VALUE” but in updation I’m facing issue.
Giving command :
sed -i “s/access_token\s*=.*/access_token = "${env.TOKEN_VALUE}"/g” providers.tf
But the Value I’m getting in variable.tf is :
provider “artifactory” {
url = “https://jfrog…/ui/login/”
access_token = “${env.TOKEN_VALUE}”
check_license = false

I’m just learning about terraform, but can’t you make a new variable artifactory_token { secret = true }, and then set TF_VAR_ARTIFACTORY_TOKEN and use ${var.artifactory_token} in your code? seems better than using sed.

Hi there,

“it doesn’t work” is always hard to remote debug. Try to always include these 3 things.

  1. what did you try? (Code samples, command lines, screenshots, videos, etc)
  2. what did happen? (Error messages, description, outputs, stuff)
  3. what did you expect to happen?

Otherwise, it’s hard for us to get into your context and you’ll have to have someone who is exactly knowledgeable come along.

@halkeye I’m using sed in jenkins job not in Terraform, basically you can consider it as another file where we want to update the value of a variable by taking it from an env variable of jenkins.
But instead of printing the value it’s adding the same ${env.TOKEN_VALUE}, but here we expect the value of new generated token.
So do we have option to use other command here

I still think the sed to replace files with a string is the wrong way to go, but without seeing the actual commands you are running with the actual things not working, my guess is its a quotes issue. Single quotes pass the string directly to shell and let shell do the replacement, and double quotes process the string before its fed to the step/command/etc and do the replacement there.

since env dot is very much a groovy/jenkinsfile, it needs to be handled by groovy, or you need to drop the env dot part, and let it be handled by bash.