From 3028ffc459ba5683f8a17cc839eb50fed5700b4e Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 10 Jun 2022 11:05:21 +0200 Subject: [PATCH 1/4] README change slave/agent --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36a46a5..0588485 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Jenkins Pipeline script to manage one or more gCube components deployment * [Pipeline: Maven](https://plugins.jenkins.io/pipeline-maven) * [Pipeline: Basic Steps](https://plugins.jenkins.io/workflow-basic-steps) * [Email Extension](https://plugins.jenkins.io/email-ext) (to send emails with attachments) -* Jenkins slave(s) configured with Ansible ver. 2.9.27 or newer +* Jenkins agent(s) configured with Ansible ver. 2.9.27 or newer * One or more Jenkins agents labeled as 'CD' ## Expected parameters From 4f2aeb59200c807f81b4ce953c07834811c15815 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 21 Jun 2022 15:47:38 +0200 Subject: [PATCH 2/4] add input parameters in order to launch the pipeline manually; add new stage dedicated to the manually execution --- Jenkinsfile | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bf4f368..ddf305a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,6 +25,15 @@ if (params.deployFile) { } backupList = agent_root_folder+'/'+agent_deploy_backup_filename; +//locate the targetHost file +//String targetHostURL = "https://code-repo.d4science.org/gCubeCI/gCubeDeployer/raw/branch/master/open/gcube-${gCube_release_version}.yaml" +//if (verbose) +// println "Querying ${targetHostURL}" +//load the release file +//def text = targetHostURL.toURL().getText() + + + pipeline { agent { label 'CD' @@ -50,7 +59,23 @@ pipeline { TRIGGER_HOST="${params.TRIGGER_HOST}" TRIGGER_CD="${params.TRIGGER_CD}" } - + + parameters { + string(name: 'TRIGGER_JOB', + defaultValue: '', + description: 'Name of the service or job to deploy') + string(name: 'TRIGGER_VERSION', + defaultValue: '', + description: 'service version to deploy') + string(name: 'TRIGGER_HOST', + defaultValue: '', + description: 'Target Host / Host group where deploy the service') + booleanParam(name: 'TRIGGER_CD', + defaultValue: true, + description: 'Set to false to avoid current deploy') + + } + stages { stage('Initialize environment') { steps { @@ -71,7 +96,7 @@ pipeline { echo 'Cron build enabled. Deploy from system ongoing' script { // parse the report and extract the data - def components = gettComponentsFromCSV(deployList) + def components = getComponentsFromCSV(deployList) if (components.size() > 0) { for (component in components) { stage(component){ @@ -147,6 +172,24 @@ pipeline { } } + stage('Deploy manually ') { + when{ + allOf{ + environment name: 'IS_CRON', value: 'False'; + triggeredBy 'UserIdCause' + } + } + steps { + echo "Cron build disabled. Pipeline executed Manually. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing" + ansiColor("xterm") { + catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { + checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); + deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); + } + } + + } + } } post { always { From 8ced60db1b666d3f2fe3a5918247e6be102e1983 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 21 Jun 2022 17:24:56 +0200 Subject: [PATCH 3/4] add check on latest: if latest then deploy allowed --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index ddf305a..ea7a287 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -258,6 +258,7 @@ def checkup(String service, String version, String host){ sh(""" case "$version" in **SNAPSHOT) echo "version contains SNAPSHOT" ;; + **latest) echo "version contains latest" ;; * ) echo "version without SNAPSHOT. EXIT WITHOUT DEPLOY "; exit 1;; esac """) From 2bde8be50d3824e672469b59e58e119d61da865f Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Wed, 22 Jun 2022 17:08:41 +0200 Subject: [PATCH 4/4] WIP add deploy report input param --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index ea7a287..a1e7b52 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -73,6 +73,9 @@ pipeline { booleanParam(name: 'TRIGGER_CD', defaultValue: true, description: 'Set to false to avoid current deploy') + string(name: 'report', + defaultValue: '', + description: 'The deploy report. Leave blank to pull the build report from Git.') }