microsoft / azure-pipelines-yaml

Azure Pipelines YAML examples, templates, and community interaction
MIT License
1.22k stars 939 forks source link

Introduce a hashstring(...), uniquestring() and safestring(...) functions #281

Closed mitchdenny closed 5 years ago

mitchdenny commented 5 years ago

I'd like to propose that Azure Pipelines introduce three new functions that can be used within templates, they would be:

hashstring(...), uniquestring() and safestring(...)

Here is why each would be useful:

Here is how I would use safestring(...) as an example. I have a template that uses ${{each ...}} to emit stages based on the items in a YAML array. However I want a stage that is dependent on all those stages. Unfortunately the items in the list are not safe strings in terms of job and stage names and so I need a function that I can use to translate the item into the list to a job name. I would then use another ${{each ...}} to emit the dependsOn attribute on the follow on stage.

mitchdenny commented 5 years ago

@vtbassmatt what are your thoughts on this? If this is something that you are interested in I would be happy to work on the implementation.

vtbassmatt commented 5 years ago

I'm not opposed. As you're doubtless aware, you'd have to land that in the Azure Pipelines service codebase. A good start would be a design doc we can bash on first. While I want to work in the open as much as we can, I think for this, we'd start with a doc in a private repo (since it covers closed-source product code).

mitchdenny commented 5 years ago

OK - sounds like a plan. I'll get something to you.

dperez83 commented 1 month ago

Hello @mitchdenny @vtbassmatt

I see this was closed as completed on 2019. Are these 3 functions (hashstring, uniquestring and safestring) live and working in Azure pipelines yml? I cannot use safestring on Azure pipelines. I needed this to make the project name suitable to a deployment name and through my searches I ended here.

And they're not listed on the official page for expressions: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops

Thank you!

mitchdenny commented 1 month ago

I don't think it ended up being implemented.

dperez83 commented 1 month ago

I don't think it ended up being implemented.

Can you open a new issue so it stays on the radar? Those 3 functions are absolutely useful when we need to create a unique name (that is required in the pipelines). I ended up using the replace function to get rid of the forbidden chars but the safestring is absolutely what I need and 1000 times better and future proof.

I would also add a guid function so it will be easy to create a unique name any time.

Thank you!