Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define random strings #1346

Open
Sopka opened this issue Sep 23, 2023 · 1 comment
Open

define random strings #1346

Sopka opened this issue Sep 23, 2023 · 1 comment
Labels
type: proposal A ticket that proposes a new feat/enhancement.

Comments

@Sopka
Copy link

Sopka commented Sep 23, 2023

I need a constant random string available during the execution of one task.
For example to append a suffix to a resource name.

My current workaround is to assign a dynamic variable and process the output further with a golang template:

tasks:
  add-suffix:
    vars:
      SUFFIX: 
        sh: uuidgen
    cmds:
      # Select the first part of a uuid for a short random string number:
      # Outputs e.g. e01136af instead of e01136af-30d6-4b6b-9c68-f52fcaaaf313
      - echo {{index (.SUFFIX | splitList "-") 0}}

I do this, because you cannot just export a shell variable at one command and re-use it in subsequent commands.

But this workaround is not OS independent and cumbersome.

Is there an easier way?

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 23, 2023
@pd93
Copy link
Member

pd93 commented Dec 17, 2023

Hi @Sopka, there is currently no built-in way to do this in Task. Unfortunately, the rand functions were removed from our templater to make it slimmer (since they rely on the rather large crypto/rand package), so you are left to call an external program like uuidgen for this task as you have suggested.

I will leave this issue open for now so that we can track it as a feature request. If others find themselves needing this functionality, please feel free to add a comment or 👍 the OP to let us know.

@pd93 pd93 added type: feature A new feature or functionality. type: proposal A ticket that proposes a new feat/enhancement. and removed state: needs triage Waiting to be triaged by a maintainer. type: feature A new feature or functionality. labels Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: proposal A ticket that proposes a new feat/enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants