Add Assignment 6 Python application and Jenkins pipeline
myfileagent-python-ci/pipeline/head This commit looks good
myfileagent-python-ci/pipeline/head This commit looks good
This commit is contained in:
parent
4a67a09780
commit
041adfcda4
Vendored
+29
@@ -0,0 +1,29 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
options {
|
||||||
|
skipDefaultCheckout()
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
timeout(time: 5, unit: 'MINUTES')
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||||
|
timestamps()
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
sh 'git rev-parse HEAD'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Syntax check') {
|
||||||
|
steps {
|
||||||
|
sh 'python3 --version'
|
||||||
|
sh 'python3 -m py_compile pricing.py tests/test_pricing.py'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Test') {
|
||||||
|
steps {
|
||||||
|
sh 'python3 -m unittest discover -s tests -v'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Assignment 6 Python CI
|
||||||
|
|
||||||
|
The pipeline runs on the trusted Jenkins controller executor. Only trusted
|
||||||
|
team members may change pipeline code. Do not supply secrets or privileged
|
||||||
|
Docker access to untrusted pull requests. Fork PR discovery is disabled.
|
||||||
|
|
||||||
|
The controller uses the official Jenkins LTS image recorded in compose.jenkins.yaml.
|
||||||
|
Python comes from that image's Debian package repositories; record the actual
|
||||||
|
Python version from each build. No pip dependencies or Docker socket are needed.
|
||||||
|
After replacing the container, run `sh ops/jenkins/install-python.sh` on the
|
||||||
|
Droplet before building. A restart retains Python; replacement requires reinstall.
|
||||||
|
Jenkins jobs and settings persist in the jenkins-home volume.
|
||||||
|
|
||||||
|
From the repository root, reproduce checks with:
|
||||||
|
|
||||||
|
python3 -m py_compile pricing.py tests/test_pricing.py
|
||||||
|
python3 -m unittest discover -s tests -v
|
||||||
|
|
||||||
|
Expected: both tests pass. Syntax or test failures must fail the Jenkins run.
|
||||||
|
Multibranch origin PR discovery tests the current PR revision, not a merged revision.
|
||||||
|
The printed checkout commit identifies what was actually tested.
|
||||||
|
|
||||||
|
Webhook delivery, status reporting, branch protection, and the controlled
|
||||||
|
failure/repair demonstration must be configured and verified separately.
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
services:
|
||||||
|
jenkins:
|
||||||
|
image: jenkins/jenkins@sha256:a660310e39ade10631f774bacd5219de767dfd08947ea5c32a739b5e5bb382c1
|
||||||
|
container_name: myfileagent-jenkins
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
JAVA_OPTS: "-Xms64m -Xmx256m"
|
||||||
|
mem_limit: 448m
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:8080"
|
||||||
|
volumes:
|
||||||
|
- jenkins-home:/var/jenkins_home
|
||||||
|
networks:
|
||||||
|
- gitea-private
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
jenkins-home:
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Run on the Droplet after recreating the official Jenkins container.
|
||||||
|
# Python installed in the container survives restart, not container replacement.
|
||||||
|
set -eu
|
||||||
|
docker exec -u root myfileagent-jenkins sh -c 'apt-get update -qq && apt-get install -y --no-install-recommends python3'
|
||||||
|
docker exec myfileagent-jenkins python3 --version
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
def total_price(unit_price, quantity):
|
||||||
|
if quantity < 1:
|
||||||
|
raise ValueError("Quantity must be positive")
|
||||||
|
return unit_price * quantity
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import unittest
|
||||||
|
from pricing import total_price
|
||||||
|
|
||||||
|
|
||||||
|
class PricingTests(unittest.TestCase):
|
||||||
|
def test_total(self):
|
||||||
|
self.assertEqual(total_price(10, 3), 30)
|
||||||
|
|
||||||
|
def test_invalid_quantity(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
total_price(10, 0)
|
||||||
Reference in New Issue
Block a user