Correct environment variable substitution for drone v1 with jsonnet

While rewriting old .drone.yml files to .drone.jsonnet and I faced one problem.

In yml there was a line which used variable substitution, like this:

tags: ${DRONE_BRANCH/\//-}

So, I tried to write such a jsonnet which will generate yaml as the one above. But I failed.

Maybe I missed something important? Please, help!

I recommend posting jsonnet syntax questions (or in this case jsonnet escaping) to stackoverflow using the jsonnet tag. The jsonnet folks should be able to help clear up any questions related to escaping.

Thank you for your response! @sbarzowski in the issue thread I linked argues that it’s impossible and useless to generate such a string from jsonnet. And this is a problem.



in jsonnet generates a valid yaml via ‘drone jsonnet’ which executes properly via ‘drone exec’.

If I use that generated yaml by committing it to the repo it works properly, although if I try to rely on jsonnet or starlark the substitution doesn’t happen. Interestingly only the replace substitution fails, others work properly with a generated pipeline.