I am facing problem during accessing Pipeline variable inside inline python script.
In prefious task CyberArk retrieves two passwords from vault and saves it into pipeline variables
PAS.Account1_ad_com
and
PAS.Account2_ad_com
I have a list of accounts earlies but it looks like this
[email protected],[email protected]
So in my Python Task:
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
import json
import os
vars = ${{ parameters.vars }}
alist = str("$(alist)")
pyvars = json.loads(vars .replace("'", '"'))
pyalist = alist .split(",")
yy = "$(PAS.Account1_ad_com)"
print(str(yy))
for index, account in enumerate(pyalist):
account_tmp="PAS." + account.replace(".", "_").replace("@", "_")
account_pass_tmp = "$(PAS." + account.replace(".", "_").replace("@", "_") + ")"
print(str(account_pass_tmp))
pyvars[index][account_tmp] = str(f"{account_pass_tmp}")
print(pyvars)
In this code you can see variable yy
made for tests and print after this and this works. It shows *** in pipeline so it means it returns password correctly.
But i can’t hardcode account name because its filled by user during start of the pipeline (in parameters), so i am creating this variable inside account_pass_tmp
and on the first look you can see that
yy = "$(PAS.Account1_ad_com)"
print(str(yy))
and
account_pass_tmp = "$(PAS." + account.replace(".", "_").replace("@", "_") + ")"
print(str(account_pass_tmp))
does not differ but the second one returns two strings $(PAS.Account1_ad_com)
and $(PAS.Account2_ad_com)
instead two times ***
Why it does not work as the hardcoded yy
variable?