Add jenkins charts
[it/dep.git] / smo-install / jenkins / gerrit / automatic-verify-pipeline
1 lock('smo') {
2 podTemplate(yaml: '''
3               apiVersion: v1
4               kind: Pod
5               spec:
6                 containers:
7                 - name: jenkins-ubuntu
8                   image: ubuntu:20.04
9                   command:
10                   - sleep
11                   args: 
12                   - 99d
13 ''') {
14   node(POD_LABEL) {
15       
16       def proxies=''
17       def toxLog=''
18       sh 'printenv'
19       stage('Checkout') {
20         script {
21           if (env.GERRIT_REFNAME.startsWith('refs/changes/')) {
22             echo 'PULL REQUEST case detected'
23             gitInfo =  checkout([$class: 'GitSCM', branches: [[name: 'changes/'+env.BRANCH_NAME]], extensions: [[$class: 'SubmoduleOption', recursiveSubmodules: true]], userRemoteConfigs: [[credentialsId: 'gerrit_username_pass', name: 'origin', refspec: '+refs/changes/*:refs/remotes/origin/changes/*', url: 'https://gerrit.o-ran-sc.org/r/a/it/dep']]])
24
25           } else {
26             echo 'BRANCH case detected'
27             gitInfo =  checkout([$class: 'GitSCM', branches: [[name: env.BRANCH_NAME]], extensions: [[$class: 'SubmoduleOption', recursiveSubmodules: true]], userRemoteConfigs: [[credentialsId: 'gerrit_username_pass', name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*', url: 'https://gerrit.o-ran-sc.org/r/a/it/dep']]])          
28           }
29         }
30         echo "Git: "+ gitInfo
31         gerritReview labels: [Verified: 0], message: env.HUDSON_URL+': Validating the SMO package ' + env.BUILD_URL
32       }
33       container('jenkins-ubuntu') {
34         stage ('Proxy settings') {
35           echo 'Proxy check'
36           script {
37             if (env.http_proxy) {
38               sh 'echo \'Acquire::http::Proxy "' + env.http_proxy + '";\' > /etc/apt/apt.conf.d/proxy.conf'
39               sh 'cat /etc/apt/apt.conf.d/proxy.conf'
40               sh 'echo "http_proxy = "'+env.http_proxy+' > ~/.wgetrc'
41               sh 'cat ~/.wgetrc'
42
43               sh 'echo \'Acquire::https::Proxy "' + env.http_proxy + '";\' >> /etc/apt/apt.conf.d/proxy.conf'
44               sh 'cat /etc/apt/apt.conf.d/proxy.conf'         
45               sh 'echo "https_proxy = "'+env.http_proxy+' >> ~/.wgetrc'
46               sh 'cat ~/.wgetrc'
47               
48               proxies='HTTPS_PROXY='+env.http_proxy+' '
49             }
50           }
51           sh 'printenv'
52
53         }
54         stage('Setup tools') {
55             echo 'Setup container'
56             sh 'printenv'
57
58             sh 'apt-get update -y'
59             sh 'DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata'
60             sh 'apt-get install git wget sudo -y'
61  
62             sh 'wget https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl'
63             sh 'mv kubectl /usr/bin'
64             sh 'chmod a+x /usr/bin/kubectl'
65
66             sh proxies+' ./smo-install/scripts/layer-0/0-setup-tests-env.sh'
67             sh proxies+' ./smo-install/scripts/layer-0/0-setup-charts-museum.sh'
68             sh proxies+' ./smo-install/scripts/layer-0/0-setup-helm3.sh'
69             sh 'kubectl version'
70         }
71         stage('Build ONAP charts') {
72             sh proxies+' ./smo-install/scripts/sub-scripts/build-onap.sh'
73         }
74         stage('Build ORAN charts') {
75             sh proxies+' ./smo-install/scripts/sub-scripts/build-oran.sh'
76         }
77         stage('Build TESTS charts') {
78             sh proxies+' ./smo-install/scripts/sub-scripts/build-tests.sh'
79         }
80         stage('Start SMO') {
81             sh './smo-install/scripts/layer-2/2-install-oran.sh pythonsdk-tests'
82         }
83         stage('Test ORAN') {
84             dir("smo-install/test/pythonsdk") {
85               echo 'Executing TOX tests'
86               try {
87                 if (env.http_proxy) {
88                   sh script: proxies+' NO_PROXY='+env.no_proxy+' tox > tox.log'
89                 } else {
90                   sh script: 'tox > tox.log'
91                 }
92                 echo 'TOX tests SUCCESS'
93                 toxLog = readFile 'tox.log'
94                 echo toxLog
95                 toxLog = sh script: 'tail -40 tox.log',returnStdout: true
96                 
97                 gerritReview labels: [Verified: 0], message:env.HUDSON_URL+': SMO Build SUCCESSFUL ('+env.BUILD_URL+')\r\n\r\n'+toxLog
98                 //gerritCheck checks: ['SMO:checker': 'SUCCESSFUL']
99                 currentBuild.result = 'SUCCESS'
100               }
101               catch(exec) {
102                 echo 'TOX tests FAILURE'
103                 toxLog = readFile 'tox.log'
104                 echo toxLog
105                 toxLog = sh script: 'tail -40 tox.log',returnStdout: true
106
107                 gerritReview labels: [Verified: 0], message:env.HUDSON_URL+': SMO Build FAILED, TOX tests have crashed ('+env.BUILD_URL+')\r\n\r\n'+toxLog
108                 //gerritCheck checks: ['SMO:checker': 'FAILED']
109                 currentBuild.result = 'FAILURE'
110               }
111             }
112         }
113         stage('Stop SMO') {
114           sh './smo-install/scripts/sub-scripts/uninstall-nonrtric.sh'
115           sh './smo-install/scripts/sub-scripts/uninstall-onap.sh'
116         }
117         stage('Get Results') {
118           archiveArtifacts artifacts: 'smo-install/test/pythonsdk/src/orantests/pythonsdk.debug.log, **/reports/junit/*.xml', fingerprint: true
119           junit '**/reports/junit/*.xml'
120
121         }
122       }
123    
124   }
125 }
126 }