Closed mitchdenny closed 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.
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).
OK - sounds like a plan. I'll get something to you.
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!
I don't think it ended up being implemented.
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!
I'd like to propose that Azure Pipelines introduce three new functions that can be used within templates, they would be:
hashstring(...)
,uniquestring()
andsafestring(...)
Here is why each would be useful:
hashstring(...)
: Given a set of string values, compute a hash which is unique based on the input values. I'd imagine this being a cryptographic hash value.uniquestring()
: Output a unique string - this would typically be placed into a parameter value so it could be reused across the template. It would be unique to each run.safestring(...)
: Similar in intent tohashstring(...)
but the output is designed to take something that is not safe for use as say a job or stage name and replace invalid characters so that it is. However it differs fromhashstring(...)
in that the output is predictable whilst authoring templates so you can reference the string in other stages.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 thedependsOn
attribute on the follow on stage.