How to reference an Environment property from the custom headers of a request
I need some help with my usage or syntax reading an Environment property. I have a custom header property that I need to add to every request. In essence it defines the back-end that goes with each of my environments, so it makes the most sense to instead have it as a custom property for each environment I have setup in the Environments section. This part makes sense, but when I try to reference that Env property from the header it does not seem to be picking it up.
Here is what I'm trying to add in a request header called FirmId:
${#Env#FirmId}
I'm thinking this 'should' read the FirmId property assigned to the environment that I have selected. So far no luck.
Thanks,
Mike
Are you talking about using the custom properties that are displayed in the Environment dialog box? If so these are project custom properties.
While I have never referenced them for the exact scenario you describe, via Groovy script you would reference them by with the following property expansion syntax:
${#Project#FirmId}
Might be worth a try...
mwalter wrote:Hmmm....this is rather interesting. I ran your example and saw the same issue as you. Then I re-ran mine, and it is also now showing the same problem where it previously worked.
OK I figured out how to make this work. The idea is to perform the property expansion using the context variable because that's what is available within the scope of the script when RequestFilter is used.
def key = context.expand('${#Project#az_key}')
Then i can use key as a variable to set the header i need:
headers.put("Authorization", key)
Hope this helps others!
dg3781,
Yes, that actually does help and works well. So thank you for that. It still baffles me why the original solution stopped working. My initial thought was that something changed with the 1.9.0 version because I did upgrade in between these 2 attempts but whatever, after I applied your change my script started working again.