feat: sample of force use specific jenkins agent #2

Merged
joy merged 9 commits from tw-dev into master 2025-09-10 00:06:10 +09:00
3 changed files with 36 additions and 34 deletions

2
.gitignore vendored
View File

@ -124,4 +124,4 @@ Temporary Items
Report
test-reports
.idea
.env
.env

View File

@ -6,15 +6,14 @@ ENV DISPLAY=:99
RUN apt-get -y update
tzuwei-huang marked this conversation as resolved Outdated
Outdated
Review

Docker file should be split for each layers.

Docker file should be split for each layers.
RUN apt-get install -y p7zip-full
RUN useradd -ms /bin/bash -u 1000 jenkins && \
echo "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN useradd -ms /bin/bash -u 1000 jenkins && echo "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
WORKDIR /app
COPY requirements.txt .
RUN pip3 install --upgrade pip && \
pip3 install --no-cache-dir -r requirements.txt && \
pip3 install --no-cache-dir pytest
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --no-cache-dir pytest
COPY . .

59
Jenkinsfile vendored
View File

@ -1,35 +1,38 @@
properties([
parameters([
string(
name: 'TEST_MARK',
defaultValue: 'All',
description: 'To filter test cases, default is All'
)
])
parameters([
string(
name: 'TEST_MARK',
defaultValue: 'All',
description: 'To filter test cases, default is All'
)
])
])
node {
stage('Setup Environment') {
cleanWs()
checkout scm
node('ccis') {
stage('Setup Environment') {
cleanWs()
checkout scm
def image = docker.build('pytest-test', '.')
env.IMAGE_ID = image.id
def image = docker.build('pytest-test', '.')
env.IMAGE_ID = image.id
}
stage('Test') {
docker.image(env.IMAGE_ID).inside("--user jenkins --shm-size=1g") {
sh 'mkdir -p Report test-reports || true'
sh 'if [ -f Report_Http.zip ]; then rm Report_Http.zip; fi'
withEnv(["TEST_MARK=${params.TEST_MARK}"]) {
sh 'python3 exec.py'
}
sh '7z a -tzip Report_Http.zip Report'
archiveArtifacts artifacts: 'Report_Http.zip', followSymlinks: false
archiveArtifacts artifacts: 'test-reports/**', followSymlinks: false
}
}
stage('Test') {
docker.image(env.IMAGE_ID).inside("--user jenkins --shm-size=1g") {
withEnv(["TEST_MARK=${params.TEST_MARK}"]) {
sh 'python3 exec.py'
sh '7z a -tzip Report_Http.zip Report'
archiveArtifacts artifacts: 'Report_Http.zip', followSymlinks: false
archiveArtifacts artifacts: 'test-reports/**', followSymlinks: false
}
}
}
stage('Prepare Report') {
junit testResults: 'test-reports/junit-report.xml', allowEmptyResults: true
}
stage('Prepare Report') {
junit testResults: 'test-reports/junit-report.xml', allowEmptyResults: true
}
}