aboutsummaryrefslogtreecommitdiff
path: root/bigtop-ci/jenkins/jobsCreator.groovy
blob: 36c0f3ef41fbd838d90be3d851bfd0ad760cce70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// FIXME: it would be nice to extract the following from bigtop.mk on the fly
def bigtopComponents = ["bigtop-groovy", "bigtop-jsvc", "bigtop-tomcat", "bigtop-utils", 
                        "zookeeper", "hadoop", "hbase", "hive", "pig", "crunch", "datafu", 
                        "flume", "giraph", "gridgain-hadoop", "mahout", "oozie", "phoenix", 
                        "solr", "spark", "sqoop", "tachyon", "whirr"]
// FIXME: it would be nice to extract the following from some static configuration file
def targetOS = ["fedora-20",  "opensuse-12.3",  "ubuntu-14.04"]
def gitUrl = "https://git-wip-us.apache.org/repos/asf/bigtop.git"
def gitBranch = "master"
def dockerLabel = "docker"
def jobPrefix="Bigtop"
def pkgTestsuites =["TestPackagesBasicsWithRM", "TestPackagesPseudoDistributedServices", 
                    "TestPackagesPseudoDistributedDependency", "TestPackagesPseudoDistributedFileContents", 
                    "TestPackagesPseudoDistributedWithRM", "TestPackagesBasics"]

job {
    name "${jobPrefix}-${gitBranch}-All"
    description "Top level job that kicks off everything for a complete Bigtop CI run on branch ${gitBranch}"
    logRotator(7 /*days to keep */, 10 /* # of builds */, 7 /*days to keep */, 10 /* # of builds */) 
    label('master')
    triggers {
      cron("0 3 * * *")
    }

    steps {
       downstreamParameterized {
          trigger("${jobPrefix}-${gitBranch}-" + bigtopComponents.join("-pkg,${jobPrefix}-${gitBranch}-") + "-pkg",
                     'UNSTABLE_OR_BETTER', true, ["buildStepFailure": "FAILURE", "failure": "FAILURE", "unstable": "UNSTABLE"]) {
            currentBuild()
          }
          
           trigger("${jobPrefix}-${gitBranch}-Repository",
                     'UNSTABLE_OR_BETTER', true, ["buildStepFailure": "FAILURE", "failure": "FAILURE", "unstable": "UNSTABLE"]) {
            currentBuild()
          }

          trigger("${jobPrefix}-${gitBranch}-Packagetest",
                     'UNSTABLE_OR_BETTER', true, ["buildStepFailure": "FAILURE", "failure": "FAILURE", "unstable": "UNSTABLE"]) {
            currentBuild()
          }
       }
    }
}

job(type: Matrix) {
    name "${jobPrefix}-${gitBranch}-Repository"
    description "Top level job that creates final repository from packages built off of ${gitBranch} branch for all the matrix"
    logRotator(2 /*days to keep */, 2 /* # of builds */, 2 /*days to keep */, 2 /* # of builds */) 
    label('master')

    steps {
      shell('''
#!/bin/bash -ex
env
rm -rf * /var/tmp/* || :

# By default Jenkins uses an internal (unresolvable) EC2 DNS name
JOB_URL="${JOB_URL/#*:/http://bigtop01.cloudera.org:}"

export PROJECTS="''' + bigtopComponents.join(' ') + '''"

mkdir -p packages
pushd packages
  for project in $PROJECTS; do
    mkdir -p ${project}
    pushd ${project}
      wget "http://bigtop01.cloudera.org:8080/job/${jobPrefix}-${gitBranch}-${project}-pkg/TARGET_OS=${TARGET_OS},slaves=docker/lastSuccessfulBuild/artifact/*zip*/archive.zip"
      unzip archive.zip
      rm archive.zip
    popd
  done
popd

if [ -n "find packages -iname '*.src.rpm'`" ] ; then
  mkdir -p repo/{RPMS,SRPMS}
  mv `find packages -iname "*.src.rpm"` repo/SRPMS/
  mv `find packages -iname "*.rpm"` repo/RPMS/

  pushd repo
    createrepo .
  popd
  cat > repo/bigtop.repo << __EOT__
[bigtop]
name=Bigtop
enabled=1
gpgcheck=0
type=NONE
baseurl=${JOB_URL}/lastSuccessfulBuild/artifact/repo/
__EOT__


else
  mkdir -p repo/conf
  cat > repo/conf/distributions <<__EOT__
Origin: Bigtop
Label: Bigtop
Suite: stable
Codename: bigtop
Version: 0.3
Architectures: i386 amd64 source
Components: contrib 
Description: Bigtop
__EOT__
  for i in `find packages -name \\*.changes` ; do
    reprepro -Vb repo include bigtop $i
  done
  echo "deb ${JOB_URL}/lastSuccessfulBuild/artifact/repo/ bigtop contrib" > repo/bigtop.list
fi
              ''')
    }

    publishers {
        archiveArtifacts('repo/**/*')
    }

    axes {
        text('TARGET_OS', targetOS)
        label('slaves', dockerLabel)
    }
}

job(type: Matrix) {
    name "${jobPrefix}-${gitBranch}-Packagetest"
    description "Runs smoke tests on all packages built off of ${gitBranch} branch for all the matrix"
    logRotator(4 /*days to keep */, 4 /* # of builds */, 4 /*days to keep */, 4 /* # of builds */) 
    label('master')

    parameters {
      choiceParam("PKG_SUITE", pkgTestsuites)
    }

    scm {
      git { node -> // is hudson.plugins.git.GitSCM
        // node / gitConfigName('Bigtop')
        // node / gitConfigEmail('dev@bigtop.apache.org')

        remote {
          name(gitBranch)
          url(gitUrl)
        }
        branch(gitBranch)
      }
    }    

    steps {
      shell('''
#!/bin/bash

# Working around SuSE madness
rm -f /etc/zypp/repos.d/*Cloud* || :

export HADOOP_HOME=/usr/lib/hadoop
export HADOOP_CONF_DIR=/etc/hadoop/conf
export REPO_FILE_URL="http://bigtop01.cloudera.org:8080/view/Bigtop-trunk/job/Bigtop-trunk-Repository/label=${label/-slave/}/lastSuccessfulBuild/artifact/repo/bigtop"
export REPO_KEY_URL="http://archive.apache.org/dist/incubator/bigtop/bigtop-0.3.0-incubating/repos/GPG-KEY-bigtop"

if [ "$label" = "precise-slave" -o "$label" = "quetzal-slave" -o "$label" = "trusty-slave" ]; then
  REPO_FILE_URL="${REPO_FILE_URL}.list"
else
  REPO_FILE_URL="${REPO_FILE_URL}.repo"
fi

docker run -u `id -u` -e HOME=/var/lib/jenkins -e BIGTOP_BUILD_STAMP=.${BUILD_NUMBER}   \\
                               -v `pwd`/build/home:/var/lib/jenkins \\
                               -v `pwd`:/ws bigtop/slaves:$TARGET_OS \\
                               bash -c '. /etc/profile.d/bigtop.sh; cd /ws ; mvn \\
  -f bigtop-tests/test-execution/package/pom.xml \\
  clean verify                                   \\
  -Dbigtop.repo.file.url="'${REPO_FILE_URL}'"      \\
  -Dorg.apache.bigtop.itest.log4j.level=TRACE    \\
  -Dlog4j.debug=true                             \\
  -Dorg.apache.maven-failsafe-plugin.testInclude="**/'${PKG_SUITE}'.*"
              ''')
    }

    publishers {
        archiveJunit('**/bigtop-tests/test-execution/package/target/failsafe-reports/*.xml') {
            retainLongStdout()
        }
    }

    axes {
        text('TARGET_OS', targetOS)
        label('slaves', dockerLabel)
    }
}

bigtopComponents.each { comp->
  job(type: Matrix) {
    println comp
    name "${jobPrefix}-${gitBranch}-${comp}-pkg"
    description "Builds packages on every platform of the matrix according to the ${gitBranch} branch"
    logRotator(7 /*days to keep */, 10 /* # of builds */, 7 /*days to keep */, 10 /* # of builds */) 
    label('master')

    scm {
      git { node -> // is hudson.plugins.git.GitSCM
        // node / gitConfigName('Bigtop')
        // node / gitConfigEmail('dev@bigtop.apache.org')

        remote {
          name(gitBranch)
          url(gitUrl)
        }
        branch(gitBranch)
      }
    }

// export JAVA_OPTS="-Xmx1536m -Xms256m -XX:MaxPermSize=256m"
// export MAVEN_OPTS="-Xmx1536m -Xms256m -XX:MaxPermSize=256m"
//
// if [ -e /etc/SuSE-release ] ; then
//  export LDFLAGS="-lrt"
// fi
    steps {
      shell('''
              mkdir -p build/home || :
              docker run -u `id -u` -e HOME=/var/lib/jenkins -e BIGTOP_BUILD_STAMP=.${BUILD_NUMBER}   \\
                               -v `pwd`/build/home:/var/lib/jenkins \\
                               -v `pwd`:/ws bigtop/slaves:$TARGET_OS \\
                               bash -c '. /etc/profile.d/bigtop.sh; cd /ws ; gradle ''' + "'\"${comp}-pkg\"")
    }

    publishers {
        archiveArtifacts('output/**/*/*')
    }

    axes {
        text('TARGET_OS', targetOS)
        label('slaves', dockerLabel)
    }
  }
}