blob: d636dbcea89368576070d2903bf6d22498e50f6a [file] [log] [blame]
- job-template:
project-type: pipeline
description: '{job-description}'
sandbox: true
concurrent: true
disabled: false
dsl: |2-
def image_sha = null
def image_md5 = null
def image_name = null
def image_size = null
def storage_path = '/home/jenkins/images'
def node_name = "${{NODE_NAME}}"
def DOWNLOAD_FLAG = true
node(node_name) {{
stage("Clean Workspace") {{
step([$class: 'WsCleanup'])
}}
stage("Check already exist file") {{
try {{
def file_name = "${{IMAGE_URL}}".split('/').last()
sh "[ -f ${{storage_path}}/${{file_name}} ]"
echo "We have already downloaded the image ${{IMAGE_URL}} in ${{storage_path}}"
DOWNLOAD_FLAG = false
currentBuild.result = 'NOT_BUILT'
}} catch (e) {{
echo "We don't have an image, need to download"
DOWNLOAD_FLAG = true
}}
}}
stage("Download image") {{
if (DOWNLOAD_FLAG) {{
sh "wget --progress=dot:giga ${{IMAGE_URL}}"
image_name = sh(returnStdout: true, script: "basename ${{IMAGE_URL}}").trim()
image_size = sh(returnStdout: true, script: "stat --printf='%s' ${{image_name}}").trim()
}} else {{
echo "Skip due to DOWNLOAD_FLAG ins't true"
}}
}}
stage("Calculate sha") {{
if (DOWNLOAD_FLAG) {{
image_sha = sh(returnStdout: true, script: "sha256sum ${{image_name}} | cut -d ' ' -f 1").trim()
image_md5 = sh(returnStdout: true, script: "md5sum ${{image_name}} | cut -d ' ' -f 1").trim()
}} else {{
echo "Skip due to DOWNLOAD_FLAG ins't true"
}}
}}
stage("Save in home") {{
if (DOWNLOAD_FLAG) {{
// sh "mv ${{image_name}} ${{image_name}}-${{image_md5}}"
// sh "mv ${{image_name}}-${{image_md5}} ${{storage_path}}/"
sh "mv ${{image_name}} ${{storage_path}}/"
}} else {{
echo "Skip due to DOWNLOAD_FLAG ins't true"
}}
}}
stage("Create source file") {{
if (DOWNLOAD_FLAG) {{
sh """
touch image_data.txt
echo IMAGE_URL=${{IMAGE_URL}} >> image_data.txt
echo IMAGE_SHA256=${{image_sha}} >> image_data.txt
echo IMAGE_MD5=${{image_md5}} >> image_data.txt
echo IMAGE_NAME=\$(basename ${{IMAGE_URL}}) >> image_data.txt
echo IMAGE_PATH=${{storage_path}}/${{image_name}} >> image_data.txt
echo IMAGE_DOWNLOADED=\$(date +%Y%m%d%H%M%S) >> image_data.txt
"""
sh """
touch image_data.json
cat << EOM > image_data.json
{{
"IMAGE_URL": "${{IMAGE_URL}}",
"IMAGE_SHA256": "${{image_sha}}",
"IMAGE_MD5": "${{image_md5}}",
"IMAGE_NAME": "\$(basename ${{IMAGE_URL}})",
"IMAGE_PATH": "${{storage_path}}/${{image_name}}",
"IMAGE_DOWNLOADED": "\$(date +%Y%m%d%H%M%S)"
}}
EOM
"""
}} else {{
echo "Skip due to DOWNLOAD_FLAG ins't true"
}}
}}
stage("Save artifacts") {{
if (DOWNLOAD_FLAG) {{
archiveArtifacts allowEmptyArchive: false,
artifacts: "image_data.*"
}} else {{
echo "Skip due to DOWNLOAD_FLAG ins't true"
}}
}}
}}
name: download-config-drive
logrotate:
DaysToKeep: 365
artifactDaysToKeep: 60
parameters:
- string:
default: ''
description: ''
name: IMAGE_URL
- string:
default: offline-deploy
description: ''
name: NODE_NAME