I’m going to create CI (Continuous Integration) Pipelines for Python project. The pipeline will include build, test, packaging and artifact storage. Furthermore, the pipeline will be automatically triggered when the source code changes (A push to a project in GitLab should trigger the build job).
Create Jenkins Job and Integration with GitLab
GitLab:
Create a new project called point and make it an internal repository.
Push the Python code. and create an Access Token for your account (User Dropdown -> Settings -> Access Tokens)
Give it a name of jenkins_svc
Check the read_repository and write_repository scopes
Create the personal access token and save the token value
Login to Jenkins
Create a new build job:
- Select New Item
- Name it “Point”
- Select Freestyle Project
- Press OK
Configure the build job:
- In Source Code Management, select Git
- Repository URL is the https URL of you Point project from GitLab (i.e., clone URL)
- You should see an error that it cannot connect to the repo
- Select Add -> Credentials and enter your Access Token name and Password. Give it an ID of jenkins_svc.
- The error should go away if the Access Token is correct
- Press Save
Run the build job:
- Select Configure
- Under Build, select Add Step -> Execute Shell
- Add the following command:
python3 -m unittest test_point_manager
Press Save.
SSH into Jenkins VM and add the following to your dockerfile
USER root
...
RUN apt-get update
RUN apt-get install -y python3 python3-pip
RUN pip3 install SQLAlchemy
RUN pip3 install --upgrade pip
Run the docker stop, build and start command from Step 3 to re-build and re-start your Jenkins
image.
Re-run the build job. It should now be successful.
View the Console Output to make sure the unittests have run and all passed.
To see the Console Output, select on the build job in the History and the Console Output
option should appear on the left side
The Output should be like this: