- For testing, which using
- Pytest framework
- Jenkins
- Allure report
- Docker
- Support testing
- Restful api testing (Testing resouces : https://fakerestapi.azurewebsites.net)
git ls-tree -r --name-only HEAD | tree --fromfile
.
├── .gitignore
├── README.md
├── business
│ ├── api_request.py
│ ├── books
│ │ ├── books_api.py
│ │ └── books_database.py
│ ├── database_execution.py
│ └── users
│ ├── users_api.py
│ └── users_database.py
├── configurations
│ ├── __init__.py
│ ├── api_domain.py
│ └── database.py
├── conftest.py
├── deployments
│ ├── Dockerfile
│ ├── Jenkinsfile
│ └── job_configurations.json
├── logger.py
├── requirements.txt
└── test_suites
├── test_books
│ └── test_get_books_id.py
└── test_users
├── test_get_users.py
└── test_post_users.py
Input the command
docker build -t pytest_learn_image -f ./deployments/Dockerfile .
Ref: How to Run Jenkins Container as Systemd Service with Docker
- Build a Jenkins run in Docker
--name jenkins
: Container naming-p 8080:8080
: Container 8080 port mapping to localhost 8080 port, which for jenkins administrator login.-p 50000:50000
Container 50000 port mapping to localhost 50000 port, which for jenkins slave node's JNLP (Java Web Start) port.-v ~/jenkins_home:/var/jenkins_home
: Build up docker volume. Container /var/jenkins_home mapping to localhost ~/jenkins_home.-v /var/run/docker.sock:/var/run/docker.sock
: Let containers can use docker daemon.
$ docker run --name jenkins -p 8080:8080 -p 50000:50000 -v ~/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins:lts
- Started the container and command for installation
$ apt-get update
$ apt install python3
$ apt install python3.11-venv
$ apt-get install -y wget
$ wget https://github.com/allure-framework/allure2/releases/download/2.14.0/allure-2.14.0.zip
$ unzip allure-2.14.0.zip
$ export PATH=$PATH:/path/to/allure-2.14.0/bin
Note: If docker cli encountering no permission
$ docker exec -u 0 -it {#CONTAINER_ID} /bin/bash
-
Launch browser way to http://localhost:8080/
a. Unlock the Jenkins with password. The password form container's logs when u started the container.
b. Install suggested plugins. Ref. How to Run Jenkins Container as Systemd Service with Docker -
Change Jenkinsfile configurations
a.GIT_REPO
: Ur repo
b._GIT_CREDENTIALS_ID
: From Jenkins credentials setting Ref How To Add Git Credentials In Jenkins
Ref. Configuring the Git Credentials in Jenkins -
Change job configurations In this case, the pipeline job will separate by services.
Thus, We may create the pipeline by services.
Before create the Jenkins pipeline, we need to add job injob_configuration.json
. \
└── test_suites
├── test_books
│ └── test_get_books_id.py
└── test_users
├── test_get_users.py
└── test_post_users.py
-
Do the config
Repository URL
: # Git repoCredentials
: Ref. Configuring the Git Credentials in JenkinsBranches to build
: */masterScript Path
: deployments/Jenkinsfile