Merge branch 'Add-Version-Templates' into 'master'

feat(UpdateVersion): Add templates and pipelines to update versions

See merge request gilden/ci/gitlab-ci-templates!2
This commit is contained in:
Karina Schaeffler 2021-07-08 12:21:39 +00:00
commit 556f0c7eb3
14 changed files with 268 additions and 5 deletions

View File

View File

@ -23,7 +23,7 @@
.publish-image-kaniko: .publish-image-kaniko:
image: image:
name: gcr.io/kaniko-project/executor:debug name: gcr.io/kaniko-project/executor:v1.6.0-debug
entrypoint: [ "" ] entrypoint: [ "" ]
stage: package stage: package
rules: rules:

View File

@ -25,8 +25,8 @@ include:
- 'npm-test-template.gitlab-ci.yml' - 'npm-test-template.gitlab-ci.yml'
- 'container-publish.gitlab-ci.yml' - 'container-publish.gitlab-ci.yml'
- 'container-scan.gitlab-ci.yml' - 'container-scan.gitlab-ci.yml'
- 'set-version-template.yml' - 'set-version-template.gitlab-ci.yml'
- 'sonar-template.yml' - 'push-tag-and-version-template.gitlab-ci.yml'
test-image: test-image:

View File

@ -0,0 +1,102 @@
:sourcedir: ../../../pipelines
ifndef::imagesdir[]
:imagesdir: ../../images
endif::[]
= update-version-pipeline
This pipeline provides the jobs to increase the version, create a new tag and updates the changed files (version) the repository.
It can be extended to push a docker image to a docker registry.
== Setup
This pipeline should be included as a child-pipeline in your gitlab-ci pipeline.
You then can add an individual release job for each kind of version bump.
NOTE: You only need the variable `PARENT_PIPELINE_ID` , if you use an https://docs.gitlab.com/ee/ci/yaml/README.html#artifact-downloads-to-child-pipelines[artifact of you parent-pipeline in your child pipeline]
In your gitlab-ci.yml include the following
.gitlab-ci.yml
[source, yaml]
----
stages:
- release
include:
- project: 'gilden/ci/gitlab-ci-templates'
ref: 'master'
files:
- 'release-template.yml'
a.major-release:
extends: .release-template
variables:
BUMP_VERSION: "major"
b.minor-release:
extends: .release-template
variables:
BUMP_VERSION: "minor"
c.patch-release:
extends: .release-template
variables:
BUMP_VERSION: "patch"
d.prerelease-release:
extends: .release-template
variables:
BUMP_VERSION: "prerelease"
e.build-release:
extends: .release-template
variables:
BUMP_VERSION: "build"
----
Create a child-pipeline file called `release.gitlab-ci.yml` and include the following:
.release.gitlab-ci.yml
[source, yaml]
----
stages:
- set-version
- push-tag-and-version
- release
include:
- project: 'gilden/ci/gitlab-ci-templates'
ref: 'master'
file:
- '/pipelines/update-version-pipeline.yml'
- 'push-image.yml'
# This is optional
push-docker-image:
stage: release
extends: .push-image-kaniko
# You only need NEED if you use a artifact from your parent pipeline to build the image
needs:
- pipeline: $PARENT_PIPELINE_ID
#Get artifacts from parent pipeline #https://docs.gitlab.com/ee/ci/yaml/README.html#artifact-downloads-to-child-pipelines
job: mvn-build
- job: increase-version
- job: push-tag-version
----
You pipeline then looks like the following:
.Release Pipeline
image::Release-Docker-Image-Pipeline.png[]
== Pipeline
.update-version-pipeline
[source, yaml]
----
include::{sourcedir}/update-version-pipeline.gitlab-ci.yml[]
----

View File

@ -0,0 +1,18 @@
:sourcedir: ../../../
= Publish-Image-jib
Baut mithilfe von jib ein Docker Image und läd es in der Docker Registry des Projekt hoch.
Dieser Schritt wird nur ausgeführt, wenn ein Tag gesetzt wird.
.Variables
|===
|Name |Description | Default Value
|MVN_VERSION | Bestimmt, ob die version von MAVEN gesetzt werden soll.
Falls das Projekt aus mehreren Poms besteht, kann `bevor_script:` benutzt werden. | "true"
|===
.publish-image-jib-template
----
include::{sourcedir}/publish-image.yml[]
----

View File

@ -0,0 +1,20 @@
:sourcedir: ../../../
= push-tag-and-version-template
This template creates a new tag und updates the version of your project in the repository.
For more details: https://gitlab.exxcellent.de/gilden/ci/exxcellent-ssh-tool[Gilde CI/CD: exxcellent-ssh-tool].
.Variables
|===
|Name |Description | Default Value
|ARTIFACT | the name of the artifact the new version is written to by the `set-version` job |"version"
|MVN_VERSION | defines if the `mvn version:set` command will be run | "true"
|===
.push-tag-and-version-template
[source, yaml]
----
include::{sourcedir}/push-tag-and-version-template.yml[]
----

View File

@ -0,0 +1,19 @@
:sourcedir: ../../../
= release-template
This template provides a template for including the child release pipeline.
For more information see the `update-version-pipeline` documentation.
.Variables
|===
|Name |Description | Default Value
|PARENT_PIPELINE_ID | The if of the parent pipeline. Needed to be able to use artifacts in the child pipeline | $CI_PIPELINE_ID
|===
.release-template
[source, yaml]
----
include::{sourcedir}/release-template.gitlab-ci.yml[]
----

View File

@ -0,0 +1,27 @@
:sourcedir: ../../../
= set-version-template
This template provides the job for increasing the tag version.
For more details look at https://gitlab.exxcellent.de/gilden/ci/exxcellent-increase-version-tool[Gilde CI/CD: exxcellent-increase-version-tool].
.Variables
|===
|Name |Description | Default Value
|BUMP_VERSION | defines the version bump | "major"
|PREFIX | the prefix for the tag | ""
|OUTPUT | defines where the updated version is written to | version
|SIMPLIFY
a|
* "false":
** use semver version number. e.g: 1.2.3+build.6
* "true":
** use more traditional version number. e.g: 1.2.3.6 | "false"
|===
.set-version-template
[source, yaml]
----
include::{sourcedir}/set-version-template.gitlab-ci.yml[]
----

View File

@ -35,9 +35,19 @@ toc::[]
include::chapters/generalInformation.adoc[leveloffset=1] include::chapters/generalInformation.adoc[leveloffset=1]
== Misc Templates == Misc Templates
//include::chapters/templates/sonar-template.adoc[leveloffset=2]
include::chapters/templates/container-publish.adoc[leveloffset=2]
include::chapters/templates/container-scan.adoc[leveloffset=2]
include::chapters/templates/container-publish.adoc[leveloffset=1] == Update Version
include::chapters/templates/container-scan.adoc[leveloffset=1]
=== Templates
include::chapters/templates/push-tag-and-version-template.adoc[leveloffset=3]
include::chapters/templates/set-version-template.adoc[leveloffset=3]
include::chapters/templates/release-template.adoc[leveloffset=3]
=== Pipeline
include::chapters/pipelines/update-version-pipeline.adoc[leveloffset=3]
== NPM Templates == NPM Templates

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -0,0 +1,22 @@
stages:
- set-version
- push-tag-and-version
include:
- project: 'gilden/ci/gitlab-ci-templates'
ref: 'master'
file:
- 'set-version-template.yml'
- 'push-tag-and-version-template.yml'
variables:
BUMP_VERSION: "major"
increase-version:
stage: set-version
extends: .set-version
push-tag-and-version:
stage: push-tag-and-version
extends: .push-tag-and-version

View File

@ -0,0 +1,20 @@
.push-tag-and-version:
stage: push-tag-and-version
image: gitlab.exxcellent.de:4567/gilden/ci/exxcellent-ssh-tool:1.2.0
variables:
ARTIFACT: "version"
MVN_VERSION: "true"
before_script:
- setup-ssh
script:
- export VERSION="0.0.0"
- "[ -f ./$ARTIFACT ] && export VERSION=$(cat ./$ARTIFACT)"
- echo $VERSION
- pull
- echo $VERSION > $ARTIFACT
- curl https://img.shields.io/badge/Version-$VERSION-green.svg --output $ARTIFACT.svg
- >
if [ "${MVN_VERSION}" == "true" ]; then
mvn versions:set -DnewVersion=$VERSION -DgenerateBackupPoms=false
fi
- push $VERSION

View File

@ -0,0 +1,11 @@
.release-template:
stage: release
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
when: manual
- when: never
variables:
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
trigger:
include: release.gitlab-ci.yml
strategy: depend

View File

@ -0,0 +1,14 @@
.set-version:
stage: set-version
image: gitlab.exxcellent.de:4567/gilden/ci/exxcellent-increase-version-tool:2.2.0
variables:
BUMP_VERSION: "major"
PREFIX: ""
OUTPUT: version
SIMPLIFY: "false"
TAG: "false"
script:
- increase-version
artifacts:
paths:
- $OUTPUT