I bought a small server in Tencent cloud
Build from scratch BI The first step of the system starts with buying a server
A scheduling system is built on it Jenkins
Tencent cloud server CentOS install Jenkins
And in codeChina There's a new one on Python Web project
After the public key is configured, you still cannot connect git The problem of
Now what I want to achieve is
① Write the project code on my computer ②push To Git Warehouse ③Git clone To server Linux On ④Python Run my project .py from ①~④ Is an infinite loop , If not used Jenkins, My process will be very complicated . Will become
Write code >>ssh
Connect to server >>cd
To project directory >>pkill
process >>rm -rf
Catalog >>git clone
project >>Python function
The whole process is very lengthy , Even a special sh file , Every time sh example.sh
To batch run from cd To python Running projects , But it is still very complicated .sh Documents should also be modified frequently . At this time, I still feel Jenkins Incomparably good , In my push After code , It only needs one key to run , I can finish from ssh To python So many steps to run , You can also do it in console Record all processes , It's just too powerful
The biggest problem is , The steps are too complicated , It just doesn't look like a BI What should be done
Create a new one sh file , The contents are as follows
pkill -9 -f main.py
rm -rf python_web
git clone https://xxx # project url
nohup python python_web.py # Operation without interruption after closing the terminal
And then every time
ssh [email protected]
cd /www/python
sh exam.sh
It's too troublesome !!!
Write a paragraph Python Code , Dozens of lines
import paramiko
ssh = ...
...
There is a problem , stay git clone I always ask for a password when I'm in , I write Going in won't solve the problem . And every update py Have to upload it again , It's a real hassle !! Not yet log
The advantage is that log
The shortcomings are too obvious
so much trouble !!
Finally, I have to Jenkins, But it's not easy , I tried it here 37 Secondary failure
To sum up the experience and the lessons of blood and tears
ERROR: Error cloning remote repo 'origin'
You need to generate a key for the machine , Paste the public key into Git platform , After this process is completed, if you still do not have permission to pull , You can refer to
After the public key is configured, you still cannot connect git The problem of
Cannot run program "cmd" (in directory...
I found that I chose the habit here perform Windows Batch command
, Should be changed into perform shell
+ python pyweb/main.py
Traceback (most recent call last):
File "pyweb/main.py", line 2, in <module>
import tornado.httpserver
ImportError: No module named tornado.httpserver
Here is the most troublesome problem I have ever encountered , Checked a lot of plans , All say Jenkins Will be in Workspace Create a new virtual directory , therefore Python The environment is also virtual , No modules installed . But before, when the local computer was running , There was no such problem . Finally, the problem may be
The details will be discussed in detail below
Python + Py Execute file server absolute path python /www/python/pyweb/main.py
Throw the module missing error as above
Python + Py Executable files Jenkins Absolute path python /var/lib/jenkins/workspace/gittest/pyweb/main.py
Error in file not found
can't open file '/var/lib/jenkins/workspace/gittest/python_web_linux/pyweb/main.py': [Errno 2] No such file or directory
Python + Py Relative path of execution file python pyweb/main.py
Throw the module missing error as above
Python Absolute path + Py Execute file server absolute path /root/.pyenv/shims/python /www/python/pyweb/main.py
Throw the module missing error as above
Python Absolute path + Py Executable files Jenkins Absolute path /root/.pyenv/shims/python /var/lib/jenkins/workspace/gittest/pyweb/main.py
Throw the module missing error as above
can't open file '/var/lib/jenkins/workspace/gittest/python_web_linux/pyweb/main.py': [Errno 2] No such file or directory
Python Absolute path + Py Relative path of execution file /root/.pyenv/shims/python pyweb/main.py
Throw the module missing error as above
where python
,which python
Found that there are many versions of Python coexistence , So I tried python3 pyweb/main.py
After the error in the above sentence is as follows python3: command not found
I'll put it up 6 In contrast to x absolute (2x3) All the combinations have tried , The same mistake , Then I tried python3.7 pyweb/main.py
python3.8 pyweb/main.py
It's all the same command not found
error
pip install tornado
pip install pymysql
python pyweb/main.py
Report errors
commond not found
pip3 install tornado
/root/.pyenv/shims/pip install tornado
pip install pyweb/requirements.txt
pip3 install pyweb/requirements.txt
/root/.pyenv/shims/pip3 install pyweb/requirements
commond not found
/www/server/panel/pyenv/bin/pip install -r pyweb/requirements.txt
Requirement already satisfied
ImportError: No module named paramiko
Permission denied (publickey)
After trying , By arranging and combining , It is found that some of them will be executed
So uninstall python3.8, Concentrate on using 3.7
Write... On the command line
/www/server/panel/pyenv/bin/python pyweb/main.py
Successful implementation
Specify the node as Linux
Appoint Git Catalog
First create a key pair and paste , Then write the project address
Write the command line
After modifying the code each time ,push After arriving at the warehouse , Run directly from this key ! You can also view the complete record ~
A fun