Skip to content

Instantly share code, notes, and snippets.

@mat813
Last active November 25, 2023 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mat813/b7f78bcf70793212434480bfaf48675a to your computer and use it in GitHub Desktop.
Save mat813/b7f78bcf70793212434480bfaf48675a to your computer and use it in GitHub Desktop.
Get current node version from .gitlab-ci.yml
use_mynode() {
local file=${1:-.gitlab-ci.yml}
local node_version
watch_file "$file"
# NODE_VERSION: 18.2.0-alpine
node_version=$(sed -n '/NODE_VERSION:/s/NODE_VERSION:[[:space:]]*\([^-]*\)\(-.*\)\?/\1/p' $file)
if [ -z "$node_version" ]; then
# NODE_IMAGE: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:18.2.0-alpine
node_version=$(sed -n '/NODE_IMAGE:/s/.*\bnode:\(.*\)-.*/\1/p' $file)
fi
if [[ -z ${node_version:-} ]]; then
log_error "File $file does not contain NODE_VERSION or NODE_IMAGE!"
return 1
fi
log_status "Found NodeJS $node_version in $file"
use_node $node_version
layout_node
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment