diff --git a/Jenkinsfile-dataset-stats b/Jenkinsfile-dataset-stats index 1c8ec49..9fdbe09 100644 --- a/Jenkinsfile-dataset-stats +++ b/Jenkinsfile-dataset-stats @@ -2,36 +2,61 @@ pipeline { agent any parameters { - string( - defaultValue: 'z-s487177-create-dataset', - description: 'Name of the project to copy artifacts from', - name: 'PROJECT_NAME', - trim: true - ) - buildSelector( - description: 'Which build to use for copying artifacts', + choice( name: 'BUILD_SELECTOR', - defaultSelector: 'lastSuccessful()' + choices: ['lastSuccessful', 'specificBuild'], + description: 'Select build' + ) + string( + name: 'SPECIFIC_BUILD', + defaultValue: '', + description: 'Specific build to copy artifacts from', + trim: true ) } stages { - stage('Copy artifacts') { + stage('Copy Artifacts') { steps { - copyArtifacts( - fingerprintArtifacts: true, - projectName: "${params.PROJECT_NAME}", - selector: buildSelector("${params.BUILD_SELECTOR}") - ) + script { + def buildSelector + if (params.BUILD_SELECTOR == 'lastSuccessful') { + buildSelector = lastSuccessful() + } else if (params.BUILD_SELECTOR == 'specificBuild') { + buildSelector = build(params.SPECIFIC_BUILD) + } else { + error('Invalid build selector') + } + + def copyArtifactParams = [ + projectName: 's487177-create-dataset', + selector: buildSelector, + filter: 'output.txt.gz', + flatten: true + ] + + copyArtifacts(copyArtifactParams) + } } } - stage('Run script') { + + stage('Calculate Dataset Statistics') { steps { sh ''' - chmod +x dataset_stats.sh - ./dataset_stats.sh > stats.txt + #!/bin/bash + set -e + + # Count the number of lines in the input file + zcat output.txt.gz | wc -l > stats + + # Archive the stats file + tar czvf stats.tar.gz stats ''' - archiveArtifacts artifacts: 'stats.txt', fingerprint: true + } + post { + always { + archiveArtifacts artifacts: 'stats.tar.gz', fingerprint: true + } } } }