Commit 74d7f1bc authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Adding new jenkins file and script to process versions in yaml files

parent 407010bb
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
pipeline {
    options {
        disableConcurrentBuilds()
        gitLabConnection('Gitlab at 3GPP')
        gitlabBuilds(builds: ["Resolve", "Deploy"])
    }
     
	agent {label 'build.forge.etsi.org'}

	environment {
		def resolveSucceded = "false"
	}
	
	stages {
    	stage('Resolve') {
    		steps{
    		    sh 'echo Resolve stage'
                updateGitlabCommitStatus name: 'Resolve', state: 'pending'
                dir('apis') {
                    checkout changelog: true, poll: false, scm: [
                        $class: 'GitSCM', branches: [[name: "${env.gitlabAfter}"]],
                        doGenerateSubmoduleConfigurations: false,
                        extensions: [[$class: 'PreBuildMerge', options: [
                        fastForwardMode: 'FF', mergeRemote: 'origin', mergeStrategy: 'DEFAULT', 
                        mergeTarget: "${env.gitlabTargetBranch}"]]
                        ],
                        submoduleCfg: [],
                        userRemoteConfigs: [[
                        credentialsId: 'Jenkins', 
                        url: "${env.gitlabSourceRepoSshUrl}" ]]
                    ]
                    sh 'git log --oneline -n 5'
                    sh 'git status -sb'
				}
                dir('scripts'){
                    checkout changelog: false, poll: false, scm: [
                        $class: 'GitSCM', branches: [[name: '*/master']],
                        doGenerateSubmoduleConfigurations: false, extensions: [],
                        submoduleCfg: [], userRemoteConfigs: [[
                        credentialsId: 'Jenkins',
                        url: 'git@forge.3gpp.org:tools/3gpp-scripts.git']]
                    ]
                }
				updateGitlabCommitStatus name: 'Resolve', state: 'success'
				script {
					env.resolveSucceded = "true"
				}
            }
		}
		stage('Deploy') {
    		steps{
    		    updateGitlabCommitStatus name: 'Deploy', state: 'pending'
    			sh 'echo Deploy stage'
				sh 'bash ./scripts/generate-config.sh ./apis'
    			updateGitlabCommitStatus name: 'Deploy', state: 'success'
			}
		}
	}
	
    post {
		always {
            archiveArtifacts artifacts: 'CONFIG.txt', onlyIfSuccessful: true
			}
		failure {
			script {
				if (env.resolveSucceded == "false") {
					updateGitlabCommitStatus name: 'Resolve', state: 'failed'
				}
			}

			updateGitlabCommitStatus name: 'Deploy', state: 'failed'
			mail to: 'cti_support@etsi.org',
				subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
				body: "Something is wrong with ${env.BUILD_URL}"
		}
	}
}

generate-config.sh

0 → 100644
+46 −0
Original line number Diff line number Diff line
#!/bin/bash
# Copyright ETSI 2021
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
echo "------ Content of the folder ------"
ls

# If there are no YAML file, simply exit
ls | grep -q yaml
found_yaml=$?
if [ ! $found_yaml ] ; then 
    echo "-- No YAML files."
    exit 0
fi

echo "------ Installing necessary node modules -----"

cd scripts
npm install js-yaml
npm install json
cd ..

pwd
echo "------ Removing old CONFIG file ------"
rm -f CONFIG.txt

echo "------ Generating CONFIG file from all YAML files ------"

echo "------ Switching to $1 folder --------"
#cd $1
pwd 
fres=0

for i in $1/*.yaml ;  do
	echo "[$i]"
    echo "[$i]" | grep -Po "\w+\.yaml" >> CONFIG.txt ;
    node ./scripts/node_modules/js-yaml/bin/js-yaml $i > "$i.json" ;
    cat "$i.json" | node ./scripts/node_modules/json/lib/json info.version >> CONFIG.txt
    cat "$i.json" | node ./scripts/node_modules/json/lib/json externalDocs.description | grep -Po "[0-9]+[.][0-9]+[.][0-9]+" >> CONFIG.txt
    cat "$i.json" | node ./scripts/node_modules/json/lib/json info.description | grep -Po "[0-9]{4}" >> CONFIG.txt
    res=$?
    fres=$(($fres||$res))
done

# Exit code needed for jenkins to know the verdict of the build
echo "-- Final validator returns $fres."
exit $fres