Skip to content
Snippets Groups Projects
Commit be06b222 authored by Viktor Vorobev's avatar Viktor Vorobev Committed by Ugo Albanese
Browse files

Merged in NRRPLT-8297-proper-image-tag (pull request #33)

[NRRPLT-8297] Use the branch name as tag for the image to be used in CI/CD.

Approved-by: Ugo Albanese
parent 0405a146
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,21 @@ ...@@ -5,6 +5,21 @@
// https://www.jenkins.io/doc/book/pipeline/shared-libraries/ // https://www.jenkins.io/doc/book/pipeline/shared-libraries/
@Library('nrp-shared-libs@master') _ @Library('nrp-shared-libs@master') _
// Before starting pipeline, we try to get the proper image tag
def DEFAULT_BRANCH = 'development'
// selectTopicBranch function is used to choose the correct branch name as topic
// the function is defined in shared libs
//
// In case there is a PR for a branch, then Jenkins runs a pipeline for this pull request, not for the branch,
// even if there are new commits to the branch (until PR is not closed). The BRANCH_NAME variable in this case is something like PR-###
// The name of the branch which is merged is stored in CHANGE_BRANCH variable. Thus, we should choose CHANGE_BRANCH as topic
//
// If there is a branch without PR, then Jenkins creates build for it normally for every push and the branch name is stored in BRANCH_NAME variable.
// CHANGE_BRANCH is empty in this case. Thus, we choose BRANCH_NAME as topic for branches without PR.
def TOPIC_BRANCH = selectTopicBranch(env.BRANCH_NAME, env.CHANGE_BRANCH)
// We try to pull the image with the topic name, or use default tag otherwise
def IMG_TAG = checkImageTag("${TOPIC_BRANCH}", "${DEFAULT_BRANCH}")
pipeline { pipeline {
environment { environment {
USER_SCRIPTS_DIR = "user-scripts" USER_SCRIPTS_DIR = "user-scripts"
...@@ -17,24 +32,18 @@ pipeline { ...@@ -17,24 +32,18 @@ pipeline {
// GIT_CHECKOUT_DIR is a dir of the main project (that was pushed) // GIT_CHECKOUT_DIR is a dir of the main project (that was pushed)
GIT_CHECKOUT_DIR = "${env.BRAIN_SIMULATION_DIR}" GIT_CHECKOUT_DIR = "${env.BRAIN_SIMULATION_DIR}"
// selectTopicBranch function is used to choose the correct branch name as topic // That is needed to pass the variables into environment with the same name from
// the function is defined in shared libs // Jenkins global scope (def ..=..)
// TOPIC_BRANCH = "${TOPIC_BRANCH}"
// In case there is a PR for a branch, then Jenkins runs a pipeline for this pull request, not for the branch, DEFAULT_BRANCH = "${DEFAULT_BRANCH}"
// even if there are new commits to the branch (until PR is not closed). The BRANCH_NAME variable in this case is something like PR-###
// The name of the branch which is merged is stored in CHANGE_BRANCH variable. Thus, we should choose CHANGE_BRANCH as topic
//
// If there is a branch without PR, then Jenkins creates build for it normally for every push and the branch name is stored in BRANCH_NAME variable.
// CHANGE_BRANCH is empty in this case. Thus, we choose BRANCH_NAME as topic for branches without PR.
TOPIC_BRANCH = selectTopicBranch(env.BRANCH_NAME, env.CHANGE_BRANCH)
DEFAULT_BRANCH = 'development'
CODE_COVERAGE_LINE = 29 CODE_COVERAGE_LINE = 29
} }
agent { agent {
docker { docker {
label 'ci_label'
// NEXUS_REGISTRY_IP and NEXUS_REGISTRY_PORT are Jenkins global variables // NEXUS_REGISTRY_IP and NEXUS_REGISTRY_PORT are Jenkins global variables
image "${env.NEXUS_REGISTRY_IP}:${env.NEXUS_REGISTRY_PORT}/nrp:development" image "${env.NEXUS_REGISTRY_IP}:${env.NEXUS_REGISTRY_PORT}/nrp:${IMG_TAG}"
args '--entrypoint="" -u root --privileged' args '--entrypoint="" -u root --privileged'
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment