Hi everyone
I’m currently working with environment variables inside configuration pipelines, so I can use the same code for different environments or different customers even. For example, I have substituted values like API tokens with an environment variable:
basic_auth {
username = “alloy”
password = sys.env(“DEVOPS_API_KEY”)
}
For this to work I needed to add the variable to ~/.bashrc and also to the /lib/systemd/system/alloy.service file.
Now I have a use case, where I want to fetch a targets.yaml file from a remote repository using remote.http but instead of declaring the actual URL, I want to use an environment variable. This is because targets differ across multiple locations but I want to use the same configuration pipeline.
I used the same procedure as in the example with the API token but somehow alloy seems to be getting an empty string from that environment variable.
Pipeline:
remote.http “targets” {
url = sys.env("TARGETS_URL")
client {
basic_auth {
username = "alloy"
password = sys.env("DEVOPS_API_KEY")
}
}
}
bashrc:
export TARGET_URL=“https ://dev.azure.com/mycompany/…”
alloy.service:
Environment=TARGET_URL=“https ://dev.azure.com/mycompany/…”
I get the following error:
ts=2025-02-06T10:06:09.33457648Z level=error msg=“failed to fetch remote config” service=remotecfg err=“161:2: Failed to build component: building component: performing request: Get "": unsupported protocol scheme "" (and 1 more diagnostics)”
Any clues on why working with environment variables in the case of API tokens works but in the case of an URL it fails? Maybe wrong syntax in the variable definition?