Document Assignment 6 Jenkins CI in the manual (refs #14)
Add the Continuous Integration with Jenkins chapter in the eight rubric sections: deployment and persistence (capacity test, memory-limit fix, restart test), HTTPS/access/firewall with IPv4 and IPv6 exposure checks, webhook traceability with an actual deployment diagram, pipeline stages, the required pr-main merge gate, PR #15's failure/repair/review/merge sequence, credentials and controller build boundary, and controls. Update the Hosts and Passwords tables (1 GiB resize, Jenkins and ci.yebilly.me, jenkins-bot account and token hints), the title page, abstract, Document History, glossary, and AI prompt log (including Vincent's prepared Oct 19-21 record). Note that Assignment 5's PR #13 merged. Also version pipeline-graph-view and its dependencies in the Jenkins plugin lockfile, and add Vincent's source-only ci/jenkins-capacity test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import groovy.json.JsonOutput
|
||||
import hudson.init.InitMilestone
|
||||
import hudson.model.BooleanParameterDefinition
|
||||
import hudson.model.BooleanParameterValue
|
||||
import hudson.model.ParametersAction
|
||||
import hudson.model.ParametersDefinitionProperty
|
||||
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy
|
||||
import hudson.security.HudsonPrivateSecurityRealm
|
||||
import hudson.security.ACL
|
||||
import jenkins.model.Jenkins
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
// Trusted administrator bootstrap, only in a new temporary home. Never log secrets.
|
||||
def j = Jenkins.get()
|
||||
def realm = new HudsonPrivateSecurityRealm(false)
|
||||
realm.createAccount('capacity-test', UUID.randomUUID().toString() + UUID.randomUUID().toString())
|
||||
j.setSecurityRealm(realm)
|
||||
def authorization = new FullControlOnceLoggedInAuthorizationStrategy()
|
||||
authorization.setAllowAnonymousRead(false)
|
||||
j.setAuthorizationStrategy(authorization)
|
||||
j.setNumExecutors(1)
|
||||
j.setQuietPeriod(0)
|
||||
j.save()
|
||||
|
||||
def root = new File('/tmp/ssw590')
|
||||
def state = [phase: 'initializing', builds: []]
|
||||
def writeState = {
|
||||
def temporary = new File(root, 'status.next')
|
||||
temporary.text = JsonOutput.toJson(state)
|
||||
java.nio.file.Files.move(temporary.toPath(), new File(root, 'status.json').toPath(),
|
||||
java.nio.file.StandardCopyOption.REPLACE_EXISTING,
|
||||
java.nio.file.StandardCopyOption.ATOMIC_MOVE)
|
||||
}
|
||||
writeState()
|
||||
|
||||
Thread.startDaemon('ssw590-disposable-test') {
|
||||
// The trusted bootstrap worker needs the same system identity as the init hook.
|
||||
def securityContext = ACL.as2(ACL.SYSTEM2)
|
||||
try {
|
||||
while (j.getInitLevel() != InitMilestone.COMPLETED) { Thread.sleep(1000) }
|
||||
state.plugins = j.pluginManager.plugins.collect {
|
||||
[id: it.shortName, version: it.version, active: it.isActive()]
|
||||
}
|
||||
state.failedPlugins = j.pluginManager.failedPlugins.collect { it.name }
|
||||
def requested = new File('/opt/ssw590-input/plugins.txt').readLines().findAll { it.trim() }
|
||||
requested.each { entry ->
|
||||
def (id, version) = entry.trim().split(':', 2)
|
||||
def p = j.pluginManager.getPlugin(id)
|
||||
if (p == null || !p.isActive() || p.version != version) {
|
||||
throw new IllegalStateException('Requested plugin not active at expected version: ' + id)
|
||||
}
|
||||
}
|
||||
if (state.failedPlugins || state.plugins.any { !it.active }) {
|
||||
throw new IllegalStateException('Plugin load failure; inspect recorded inventory')
|
||||
}
|
||||
// Access plugin classes only after checking that they loaded.
|
||||
def jobClass = j.pluginManager.uberClassLoader.loadClass('org.jenkinsci.plugins.workflow.job.WorkflowJob')
|
||||
def definitionClass = j.pluginManager.uberClassLoader.loadClass('org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition')
|
||||
def job = j.createProject(jobClass, 'capacity-pricing')
|
||||
job.addProperty(new ParametersDefinitionProperty(
|
||||
new BooleanParameterDefinition('BREAK_CALCULATION', false, 'Disposable failure exercise')))
|
||||
job.setDefinition(definitionClass.getConstructor(String.class, Boolean.TYPE).newInstance(
|
||||
new File('/opt/ssw590-input/fixtures/Jenkinsfile').text, true))
|
||||
job.save()
|
||||
state.phase = 'ready'
|
||||
writeState()
|
||||
// Host must observe >=60 seconds of healthy HTTP AFTER plugin checks first.
|
||||
while (!new File(root, 'start-jobs').exists()) { Thread.sleep(1000) }
|
||||
state.phase = 'pipelines'
|
||||
writeState()
|
||||
def cases = [[name: 'pass', broken: false, expected: 'SUCCESS'],
|
||||
[name: 'intentional-failure', broken: true, expected: 'FAILURE'],
|
||||
[name: 'repair', broken: false, expected: 'SUCCESS']]
|
||||
for (testCase in cases) {
|
||||
def future = job.scheduleBuild2(0, new ParametersAction(
|
||||
new BooleanParameterValue('BREAK_CALCULATION', testCase.broken)))
|
||||
if (future == null) { throw new IllegalStateException('Build could not be scheduled') }
|
||||
def build = future.get(180, TimeUnit.SECONDS)
|
||||
// Only these known fixture-job logs are copied, never controller logs.
|
||||
def console = build.getLog(500).join('\n') + '\n'
|
||||
new File(root, testCase.name + '-console.txt').text = console
|
||||
def observed = build.result.toString()
|
||||
state.builds << [name: testCase.name, number: build.number,
|
||||
expected: testCase.expected, actual: observed]
|
||||
writeState()
|
||||
if (observed != testCase.expected) {
|
||||
throw new IllegalStateException('Unexpected fixture build result: ' + testCase.name)
|
||||
}
|
||||
if (!console.contains('Ran 2 tests')) {
|
||||
throw new IllegalStateException('Unit tests did not actually execute')
|
||||
}
|
||||
if (testCase.broken && (!console.contains('13 != 30') || !console.contains('FAILED (failures=1)'))) {
|
||||
throw new IllegalStateException('Failure was not the intended calculation assertion')
|
||||
}
|
||||
}
|
||||
state.phase = 'complete'
|
||||
writeState()
|
||||
} catch (Throwable failure) {
|
||||
state.phase = 'failed'
|
||||
// Fixed harness error text/type; do not dump arbitrary stack traces or secrets.
|
||||
state.errorType = failure.class.name
|
||||
writeState()
|
||||
} finally {
|
||||
securityContext.close()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user