How to pass Jenkins variables to Packer?

679 Views Asked by At

In Jenkins it is set like:

environment {
  VARIABLE_1 = credentials('variable-1')
}

In packer how am I meant to do this, I've had a brief idea how to do it but it never seems to pick up the value:

provisioner "powershell" {
environment_vars = ["VARIABLE_1={$env:VARIABLE_1}"]
inline           = ["Write-Host \"Secret Text is: ${Env:VARIABLE_1}\""]

So my question is, what's the best way to pass through this variable and ensure packer picks this up from Jenkins?

I have tried the above but I have also tried changing the environment variable format to no avail.

I was expecting the secret text value from Jenkins to be imported into Packer(HCL format).

0

There are 0 best solutions below