From d4a1b733f4264c04d456b94ffbe111a292f82e31 Mon Sep 17 00:00:00 2001 From: Primakov Alexandr Alexandrovich Date: Mon, 5 Aug 2024 18:04:29 +0300 Subject: [PATCH] groovy test --- groovy/tag.groovy | 12 ++++++++ predeploy/Jenkinsfile | 66 +++++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 groovy/tag.groovy diff --git a/groovy/tag.groovy b/groovy/tag.groovy new file mode 100644 index 0000000..5602a19 --- /dev/null +++ b/groovy/tag.groovy @@ -0,0 +1,12 @@ +String tag = '' + +def calcTag() { + tag = sh(returnStdout: true, script: "git tag --contains").trim() + return tag +} + +def getTagNoV() { + return tag.substring(1) +} + +return this diff --git a/predeploy/Jenkinsfile b/predeploy/Jenkinsfile index 47c1733..61def5b 100644 --- a/predeploy/Jenkinsfile +++ b/predeploy/Jenkinsfile @@ -1,31 +1,43 @@ -stage ('predeploy') { - echo 'checking tag' - script { - def tag = sh(returnStdout: true, script: "git tag --contains").trim() - def branchName = sh(returnStdout: true, script: "git rev-parse --abbrev-ref HEAD").trim() +// stage ('predeploy') { +// echo 'checking tag' +// script { +// def tag = sh(returnStdout: true, script: "git tag --contains").trim() +// def branchName = sh(returnStdout: true, script: "git rev-parse --abbrev-ref HEAD").trim() - if (tag) { - echo 'found tag ' + tag - addBadge( - icon: 'completed.gif', - text: "Release ${tag}") - def tagNoV = tag.substring(1) - sh "cd ${TARGET_FOLDER}; echo '${tagNoV}' > ${DEPLOY_VERSION_VAR}"; - // sh "cd ${TARGET_FOLDER} ; echo 'mkdir ${tagNoV}; mv ./${branchName}/* ./${tagNoV}; rm -r -d ./${branchName}; rm ${DEPLOY_VERSION_VAR}' > ${DEPLOY_VERSION_VAR}" - } else { - echo 'tag not found' - addBadge( - icon: 'info.gif', - text: "Сборка в master") - sh "cd ${TARGET_FOLDER}; echo '${branchName}' > ${DEPLOY_VERSION_VAR}" - // sh "cd ${TARGET_FOLDER} ; echo 'rm ${DEPLOY_VERSION_VAR}' > ${DEPLOY_VERSION_VAR}" +// if (tag) { +// echo 'found tag ' + tag +// addBadge( +// icon: 'completed.gif', +// text: "Release ${tag}") +// def tagNoV = tag.substring(1) +// sh "cd ${TARGET_FOLDER}; echo '${tagNoV}' > ${DEPLOY_VERSION_VAR}"; +// // sh "cd ${TARGET_FOLDER} ; echo 'mkdir ${tagNoV}; mv ./${branchName}/* ./${tagNoV}; rm -r -d ./${branchName}; rm ${DEPLOY_VERSION_VAR}' > ${DEPLOY_VERSION_VAR}" +// } else { +// echo 'tag not found' +// addBadge( +// icon: 'info.gif', +// text: "Сборка в master") +// sh "cd ${TARGET_FOLDER}; echo '${branchName}' > ${DEPLOY_VERSION_VAR}" +// // sh "cd ${TARGET_FOLDER} ; echo 'rm ${DEPLOY_VERSION_VAR}' > ${DEPLOY_VERSION_VAR}" +// } +// } +// } + +// stage ('archiving') { +// // Archive the build output artifacts. +// script { +// archiveArtifacts artifacts: "${TARGET_FOLDER}/*/**" +// } +// } + +def tagModule = load "${JEN_FILES_TMP_NAME}/groovy/tag.groovy" + +stage ('predeploy 2') { + steps { + echo 'checking tag' + script { + tag = tagModule.calcTag() + echo tag } } } - -stage ('archiving') { - // Archive the build output artifacts. - script { - archiveArtifacts artifacts: "${TARGET_FOLDER}/*/**" - } -}