netci.groovy 7.7 KB
Newer Older
1 2 3
// Groovy Script: http://www.groovy-lang.org/syntax.html
// Jenkins DSL: https://github.com/jenkinsci/job-dsl-plugin/wiki

4
import jobs.generation.Utilities;
J
Jared Parsons 已提交
5 6
import static Constants.*;

7
def project = GithubProject
J
Jared Parsons 已提交
8 9 10 11 12

class Constants {
    // Number of minutes a build job is given to complete.
    static final BuildTimeLimit = 120;
}
13

14 15 16
static void addLogRotator(def myJob) {
  myJob.with {
    logRotator {
17
      daysToKeep(90)
18
      numToKeep(-1)
19 20
      artifactDaysToKeep(21)
      artifactNumToKeep(-1)
21 22 23 24
    }
  }
}

J
Jared Parsons 已提交
25
static void addConcurrentBuild(def myJob) {
26
  myJob.with {
J
Jared Parsons 已提交
27
    concurrentBuild()
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  }
}

static void addScm(def myJob, String branchName, String refspecName = '') {
  myJob.with {
    scm {
      git {
        remote {
          github('dotnet/roslyn', 'https', 'github.com')
          name('')
          refspec(refspecName)
        }
        branch(branchName)
        wipeOutWorkspace(true)
        shallowClone(true)
      }
    }
  }
}

static void addWrappers(def myJob) {
  myJob.with {
    wrappers {
      timeout {
J
Jared Parsons 已提交
52
        absolute(BuildTimeLimit)
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
        abortBuild()
      }
      timestamps()
    }
  }
}

static void addEmailPublisher(def myJob) {
  myJob.with {
    publishers {
      extendedEmail('$DEFAULT_RECIPIENTS, cc:mlinfraswat@microsoft.com', '$DEFAULT_SUBJECT', '$DEFAULT_CONTENT') {
        trigger('Aborted', '$PROJECT_DEFAULT_SUBJECT', '$PROJECT_DEFAULT_CONTENT', null, true, true, true, true)
        trigger('Failure', '$PROJECT_DEFAULT_SUBJECT', '$PROJECT_DEFAULT_CONTENT', null, true, true, true, true)
      }
    }
  }
}

static void addUnitPublisher(def myJob) {
  myJob.with {
    configure { node ->
      node / 'publishers' << {
      'xunit'('plugin': 'xunit@1.97') {
      'types' {
        'XUnitDotNetTestType' {
78
          'pattern'('**/xUnitResults/*.xml')
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
            'skipNoTestFiles'(false)
            'failIfNotNew'(true)
            'deleteOutputFiles'(true)
            'stopProcessingIfError'(true)
          }
        }
        'thresholds' {
          'org.jenkinsci.plugins.xunit.threshold.FailedThreshold' {
            'unstableThreshold'('')
            'unstableNewThreshold'('')
            'failureThreshold'('0')
            'failureNewThreshold'('')
          }
          'org.jenkinsci.plugins.xunit.threshold.SkippedThreshold' {
              'unstableThreshold'('')
              'unstableNewThreshold'('')
              'failureThreshold'('')
              'failureNewThreshold'('')
            }
          }
          'thresholdMode'('1')
          'extraConfiguration' {
            testTimeMargin('3000')
          }
        }
      }
    }
  }
}

static void addPushTrigger(def myJob) {
  myJob.with {
    triggers {
      githubPush()
    }
  }
}

117 118
// Generates the standard trigger phrases.  This is the regex which ends up matching lines like:
//  test win32 please
J
Jared Parsons 已提交
119
static String generateTriggerPhrase(String jobName, String opsysName, String triggerKeyword = 'this') {
120 121 122
    return "(?i).*test\\W+(${jobName.replace('_', '/').substring(7)}|${opsysName}|${triggerKeyword}|${opsysName}\\W+${triggerKeyword}|${triggerKeyword}\\W+${opsysName})\\W+please.*";
}

J
Jared Parsons 已提交
123
static void addPullRequestTrigger(def myJob, String jobName, String triggerPhraseText, Boolean triggerPhraseOnly = false) {
124
  myJob.with {
125 126 127 128
    triggers {
      pullRequest {
        admin('Microsoft')
        useGitHubHooks(true)
J
Jared Parsons 已提交
129
        triggerPhrase(triggerPhraseText)
J
Jared Parsons 已提交
130
        onlyTriggerPhrase(triggerPhraseOnly)
131 132 133
        autoCloseFailedPullRequests(false)
        orgWhitelist('Microsoft')
        allowMembersOfWhitelistedOrgsAsAdmin(true)
134
        permitAll(true)
135 136
        extensions {
          commitStatus {
137
            context(jobName.replace('_', '/').substring(7))
138 139 140 141 142 143 144
          }
        }
      }
    }
  }
}

J
Jared Parsons 已提交
145
static void addStandardJob(def myJob, String jobName, String branchName, String triggerPhrase, Boolean triggerPhraseOnly = false) {
146 147 148
  addLogRotator(myJob)
  addWrappers(myJob)

149
  def includePattern = "Binaries/**/*.pdb,Binaries/**/*.xml,Binaries/**/*.log,Binaries/**/*.dmp,Binaries/**/*.zip,Binaries/**/*.png,Binaries/**/*.xml"
150
  def excludePattern = "Binaries/Obj/**,Binaries/Bootstrap/**,Binaries/**/nuget*.zip"
J
Jared Parsons 已提交
151
  Utilities.addArchival(myJob, includePattern, excludePattern)
152 153

  if (branchName == 'prtest') {
J
Jared Parsons 已提交
154
    addPullRequestTrigger(myJob, jobName, triggerPhrase, triggerPhraseOnly);
155 156 157 158 159 160 161 162
    addScm(myJob, '${sha1}', '+refs/pull/*:refs/remotes/origin/pr/*')
  } else {
    addPushTrigger(myJob)
    addScm(myJob, "*/${branchName}")
    addEmailPublisher(myJob)
  }
}

A
Artur Spychaj 已提交
163
def branchNames = []
164
['master', 'future', 'stabilization', 'future-stabilization', 'hotfixes', 'prtest'].each { branchName ->
A
Artur Spychaj 已提交
165 166 167 168 169
  def shortBranchName = branchName.substring(0, 6)
  def jobBranchName = shortBranchName in branchNames ? branchName : shortBranchName
  branchNames << jobBranchName

  // folder("${jobBranchName}")
170
  ['win', 'linux', 'mac'].each { opsys ->
A
Artur Spychaj 已提交
171
    // folder("${jobBranchName}/${opsys.substring(0, 3)}")
172 173
    ['dbg', 'rel'].each { configuration ->
      if ((configuration == 'dbg') || ((branchName != 'prtest') && (opsys == 'win'))) {
A
Artur Spychaj 已提交
174
        // folder("${jobBranchName}/${opsys.substring(0, 3)}/${configuration}")
175 176
        ['unit32', 'unit64'].each { buildTarget ->
          if ((opsys == 'win') || (buildTarget == 'unit32')) {
A
Artur Spychaj 已提交
177
            def jobName = "roslyn_${jobBranchName}_${opsys.substring(0, 3)}_${configuration}_${buildTarget}"
178 179 180 181
            def myJob = job(jobName) {
              description('')
            }

182 183 184 185 186 187 188 189 190 191 192
            // Generate the PR trigger phrase for this job.
            String triggerKeyword = '';
            switch (buildTarget) {
              case 'unit32':
                triggerKeyword =  '(unit|unit32|unit\\W+32)';
                break;
              case 'unit64':
                triggerKeyword = '(unit|unit64|unit\\W+64)';
                break;
            }
            String triggerPhrase = generateTriggerPhrase(jobName, opsys, triggerKeyword);
J
Jared Parsons 已提交
193
            Boolean triggerPhraseOnly = false;
194

195 196 197 198
            switch (opsys) {
              case 'win':
                myJob.with {
                  steps {
199
                    batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
200
mkdir %TEMP%
201
set TMP=%TEMP%
L
Larry Golding 已提交
202
.\\cibuild.cmd ${(configuration == 'dbg') ? '/debug' : '/release'} ${(buildTarget == 'unit32') ? '/test32' : '/test64'}""")
203
                  }
204
                }
205
                Utilities.setMachineAffinity(myJob, 'Windows_NT', 'latest-or-auto')
206
                // Generic throttling for Windows, no category
J
Jared Parsons 已提交
207
                addConcurrentBuild(myJob)
208 209 210 211 212
                break;
              case 'linux':
                myJob.with {
                  label('ubuntu-fast')
                  steps {
213
                    shell("./cibuild.sh --nocache --debug")
214
                  }
215
                }
J
Jared Parsons 已提交
216
                addConcurrentBuild(myJob)
217 218 219 220 221
                break;
              case 'mac':
                myJob.with {
                  label('mac-roslyn')
                  steps {
222
                    shell("./cibuild.sh --nocache --debug")
223 224
                  }
                }
J
Jared Parsons 已提交
225
                addConcurrentBuild(myJob)
J
Jared Parsons 已提交
226
                triggerPhraseOnly = true;
227
                break;
228 229 230
            }

            addUnitPublisher(myJob)
J
Jared Parsons 已提交
231
            addStandardJob(myJob, jobName, branchName, triggerPhrase, triggerPhraseOnly);
232 233 234 235 236
          }
        }
      }
    }
  }
237

J
Jared Parsons 已提交
238 239 240 241
  def determinismJobName = "roslyn_${jobBranchName}_determinism"
  def determinismJob = job(determinismJobName) {
    description('')
  }
242

J
Jared Parsons 已提交
243 244 245 246
  determinismJob.with {
    label('windows-roslyn')
    steps {
      batchFile("""set TEMP=%WORKSPACE%\\Binaries\\Temp
247 248 249 250
mkdir %TEMP%
set TMP=%TEMP%
.\\cibuild.cmd /testDeterminism""")
    }
251
  }
J
Jared Parsons 已提交
252

253
  Utilities.setMachineAffinity(determinismJob, 'Windows_NT', 'latest-or-auto')
J
Jared Parsons 已提交
254
  addConcurrentBuild(determinismJob)
J
Jared Parsons 已提交
255
  addStandardJob(determinismJob, determinismJobName, branchName,  "(?i).*test\\W+determinism.*", true);
256
}
257