feat: append branch into tags if not main

This commit is contained in:
Stefan Reimer 2022-12-22 11:27:25 +00:00
parent 4b62adacb1
commit 47140c2d81
2 changed files with 12 additions and 4 deletions

View File

@ -1,12 +1,19 @@
# Parse version from latest git semver tag
BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_TAG=$(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
TAG ?= $(shell echo $(GIT_TAG) | awk -F '-' '{ print $$1 "-" $$2 }' | sed -e 's/-$$//')
# EXTRA_TAGS supposed to be set at the caller, eg. $(shell echo $(TAG) | awk -F '.' '{ print $$1 "." $$2 }')
GIT_TAG := $(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
TAG := $(GIT_TAG)
# append branch name to tag if NOT main nor master
ifeq (,$(filter main master, $(BRANCH)))
TAG = $(GIT_TAG)-$(BRANCH)
endif
# optionally set by the caller
EXTRA_TAGS :=
ARCH := amd64
ALL_ARCHS := amd64 arm64
_ARCH = $(or $(filter ${ARCH},${ALL_ARCHS}),$(error $$ARCH [${ARCH}] must be exactly one of ${ALL_ARCHS}))
_ARCH = $(or $(filter $(ARCH),$(ALL_ARCHS)),$(error $$ARCH [$(ARCH)] must be exactly one of "$(ALL_ARCHS)"))
ifneq ($(TRIVY_REMOTE),)
TRIVY_OPTS := --server $(TRIVY_REMOTE)

View File

@ -10,6 +10,7 @@ def call(Map config=[:]) {
stages {
stage('Prepare') {
steps {
// pull tags
withCredentials([gitUsernamePassword(credentialsId: 'gitea-jenkins-user')]) {
sh 'git fetch -q --tags ${GIT_URL}'
}