Looking to have Custom variable should have flag ( true / false) to decide next step if condition. Can someone please share the recommended way to achieve this?
For example
steps:
label: ‘Get Delta files and deploy artifacts’
commands:
You won’t be able to evaluate $CUSTOM_VARIABLE in your next step, as exporting the variable in the command step will result in the value only being available in the same step, as each step runs in it’s own shell.
The recommendation would be to dynamically generate the SP Config Export Objects from Sandbox, evaluating CUSTOM_VARIABLE in a script that will upload the subsequent steps to the pipeline based on its value. We have some documentation around using conditionals in steps as well that gives some more examples!
Thank you. I was trying to do following way to check and limit the steps execution. I see error when I execute following pipeline.
Can you please guide me about this error and check if we can use as I trying below.
022-11-17 11:36:43 WARN POST https://xxxx.xxxx.com/v3/jobs/018d-325797978918/pipelines: 422 One of the steps you provided was invalid: Error parsing if expression: Unexpected -: expected (, comparison operator, &&, ||, ?, or EOF (line 2, column 11) (Attempt 0/60 Retrying in -2562047h47m11.854775807s) 2022-11-17 11:36:43 ERROR Unrecoverable error, skipping retries 2022-11-17 11:36:43 FATAL Failed to upload and process pipeline: POST https://agent.buildkite.com/v3/jobs/01848671-8597-475f-8f99-325797978918/pipelines: 422 One of the steps you provided was invalid: Error parsing if expression: Unexpected -: expected (, comparison operator, &&, ||, ?, or EOF (line 2, column 11) Error: The command exited with status 1
The error is coming from your if statement in the YAML you shared:
Unfortunately, It’s not possible to evaluate the results of the buildkite-agent meta-data command as part of a conditional in your pipeline steps. What you would need to do is run a command step that gets the meta-data and checks it, then uploads the conditional step as part of the buildkite-agent pipeline upload command, like this:
- command: |
if [[ $$(buildkite-agent meta-data get "SPCONFIG") == "true" && "$BUILDKITE_BRANCH_ID" == "sv046x_vault_check" ]]; then
cat <<- YAML | buildkite-agent pipeline upload
steps:
- label: "SP Config Export Objects from Sandbox"
commands:
- pwsh .buildkite/scripts/module-sailpointutils.ps1
YAML
fi
@jeremy - Thank you. Do you know how to display the meta value after created. validatespconfig.ps1 will return true / false. I wanted to display the value to confirm about value.
- pwsh .buildkite/scripts/validatespconfig.ps1 | buildkite-agent meta-data set "SPCONFIG"
- echo "$$(buildkite-agent meta-data get "SPCONFIG")"
We would want to set values to meta-data to make it available for the other steps, so the best way to confirm and display the value is to confirm it in another step.