5-jenkins jenkins learn to pull git repository code execution python script automation

Foreword

python automated script development to be submitted after completion of git repository, the next step is to pull code to use Jenkins build automation code

git source code management

Code upload git repository is not presented here, can be seen written before this github related https://www.cnblogs.com/yoyoketang/p/7302515.html
general use gitlab own house, you can refer to this https : //www.cnblogs.com/yoyoketang/p/10282529.html

Open a new free-style project Jenkins

Source Management

  • Repository URL address code repository
  • Credentials git repository login ID and password credentials
  • The specified branch (empty behalf any) default branch*/master

Repository URL address code repository

NOTE: If ssh way linked to the upper right corner point SSH address

Credentials opening the Jenkins button, enter the git repository login ID and password

Construction of execution shell

Execute shell, first pip3 installation requirements.txt, and then execute the script pytest

Check out the console input, console View Log

+ ls
requirements.txt
test_demo.py
+ pip3 install -r requirements.txt
Collecting requests==2.18.4 (from -r requirements.txt (line 1))
  Downloading 

Installing collected packages: idna, urllib3, requests, atomicwrites, six, more-itertools, wcwidth, attrs, py, zipp, importlib-metadata, pluggy, pytest, pytest-metadata, pytest-html
  Found existing installation: idna 2.8
    Uninstalling idna-2.8:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/var/jenkins_home/python3/lib/python3.6/site-packages/idna-2.8.dist-info/INSTALLER'
Consider using the `--user` option or check the permissions.

Found no permission to install, can be installed into the interior of the container

docker exec -it -u root 容器id /bin/bash

Open workspace installation directory / home / jenkins / workspace / pytest_demo

[root@cb8e397d5308]# cd /home/jenkins/workspace/pytest_demo
[root@cb8e397d5308]# ls
requirements.txt  test_demo.py
[root@cb8e397d5308]# pip3 install -r requirements.txt

Enter pytest check pytest after the installation is complete: -bash: pytest: command not found

[root@VM_0_2_centos pytest_demo]# pytest
-bash: pytest: command not found

Find pytest installation address to add a soft link, enter pytest --version viewing environment

[root@cb8e397d5308]# find / -name pytest
/var/jenkins_home/python3/bin/pytest
[root@cb8e397d5308]# ln -s /var/jenkins_home/python3/bin/pytest /usr/bin/pytest
[root@cb8e397d5308]# pytest --version
This is pytest version 4.5.0, imported from /root/python36/lib/python3.6/site-packages/pytest.py
setuptools registered plugins:
  pytest-html-1.19.0 at /root/python36/lib/python3.6/site-packages/pytest_html/plugin.py
  pytest-metadata-1.8.0 at /root/python36/lib/python3.6/site-packages/pytest_metadata/plugin.py

Build job

After the above environment are required to complete the installation, when the implementation of the shell, pytest direct input commands can be executed automated script

Construction of success

Guess you like

Origin www.cnblogs.com/yoyoketang/p/12129847.html
Recommended