Bluestopher
Bluestopher
Explore posts from servers
TTask
Created by Bluestopher on 8/30/2024 in #help
Precondition with OR does not work
Hey all, I have a build pre condition that checks two things: production or version. If the build is production I want to validate the version in my pre condition and if the build is not production I want to continue successfully without validating the version. When I run the two expression together it fails even when I specify PRODUCTION = false. That is, if I pass PRODUCTION == false I want to skip validating the version and continue successfully and if PRODUCTION == true I want to validate the version with my regex and fail if it is not a valid format. Here is my pre condition:
preconditions:
# Validate version following semver regex validator: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string, https://github.com/har7an/bash-semver-regex
- sh: '[[ {{ .PRODUCTION }} == "false" || {{ .VERSION }} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]'
msg: Invalid semantic version format "{{ .VERSION }}"
preconditions:
# Validate version following semver regex validator: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string, https://github.com/har7an/bash-semver-regex
- sh: '[[ {{ .PRODUCTION }} == "false" || {{ .VERSION }} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]'
msg: Invalid semantic version format "{{ .VERSION }}"
If PRODUCTION == "false" I want to skip performing the version format validation in the "||" and successfully pass the pre condition.
{{ .PRODUCTION }} == "false"
{{ .PRODUCTION }} == "false"
If VERSION is not in the correct format when PRODUCTION == "true" I want to fail the pre condition.
{{ .VERSION }} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]
{{ .VERSION }} =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]
2 replies
TTask
Created by Bluestopher on 8/20/2024 in #help
Required input does not prevent dependencies from running and dependencies do not share variables
Hey all, I am running into two problems with my build release task: 1. In my dependencies section I have duplications with the variables I want to pass to each dependency. Do we have a way to pass common variables to all dependencies instead of explicitly setting them for each dependency? 2. In my requires statement I have a few required variables. If a user does not pass all the required variables I do not want my task or its dependencies to run. Currently, my dependencies will all run and then my task will fail before it executes the command. Is that the expected behavior or am I able to block all dependencies from running as well if required parameters are not passed? Here is my build release task:
build:release:
summary: Builds and packages the application for supported distributions
preconditions:
# Validate version following semver regex validator: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
- sh: '[[ {{ .VERSION }} =~ ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ ]]'
msg: Invalid semantic version format "{{ .VERSION }}"
deps:
- task: test:one
vars:
PRODUCTION: "true"
VERSION: '{{ .VERSION }}'
DATE:
sh: date -u +'%Y-%m-%dT%H:%M:%SZ'
GIT_HASH:
sh: git rev-parse --verify HEAD
- task: test:two
vars:
PRODUCTION: "true"
VERSION: '{{ .VERSION }}'
DATE:
sh: date -u +'%Y-%m-%dT%H:%M:%SZ'
GIT_HASH:
sh: git rev-parse --verify HEAD
cmds:
- echo "ran"
requires:
vars: [APPLE_USERNAME, APPLE_PASSWORD, APPLE_TEAM_ID, APPLE_APPLICATION_IDENTITY, VERSION]
build:release:
summary: Builds and packages the application for supported distributions
preconditions:
# Validate version following semver regex validator: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
- sh: '[[ {{ .VERSION }} =~ ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ ]]'
msg: Invalid semantic version format "{{ .VERSION }}"
deps:
- task: test:one
vars:
PRODUCTION: "true"
VERSION: '{{ .VERSION }}'
DATE:
sh: date -u +'%Y-%m-%dT%H:%M:%SZ'
GIT_HASH:
sh: git rev-parse --verify HEAD
- task: test:two
vars:
PRODUCTION: "true"
VERSION: '{{ .VERSION }}'
DATE:
sh: date -u +'%Y-%m-%dT%H:%M:%SZ'
GIT_HASH:
sh: git rev-parse --verify HEAD
cmds:
- echo "ran"
requires:
vars: [APPLE_USERNAME, APPLE_PASSWORD, APPLE_TEAM_ID, APPLE_APPLICATION_IDENTITY, VERSION]
3 replies