Using TXcloud or AliCloud is terrible because I need to access github and I don't want to config
Magic or Proxyon server.So I choose EC2 server then downloadeddockerthen install jenkins image.I will skip install step because it is easy.
A simple demo
After install jenkins let us create a project to learn jenkins. I choose Freestyle project although I don't know which is better.
We create a simple js project and publish it onto github.(I don't know whether Jenkinsfile is necessary.But define environment here looks like not effect freestyle project😂)
Here is some import config:
You need to generate a github token from here
Image says you need input password but username and password as github credentials is not support now.
Now this project is created.Let us have a test.
Safe and sound.But we need after git push it will trigger. Here is a important step:
I think install jenkins locally cannot receive github webhooks because local doesn't have a ip.
Then we change some code from github and jenkins will receive webhooks and automaticly run our shell command.
Add a little feature
How about we let jenkins run our js code?Change build step and run shell:
Just click Build Now to trigger shell.
Sad. It said node is not found.Let me think. Our jenkins is installed on server's docker image.So install nodejs for server is useless.How about use docker exec into container to install nodejs? I tried but failed only root user can install but I am docker user(and ChatGPT tell me after restart container may need reinstall nodejs.
The solution is install a plugin for jenkins.I will skip install plugin too.
After install a node version we need to apply it into our jenkins project.
Rebuild. Success!
Let js receive jenkins environment
I want to use jenkins build our code and set environment.
For example I want to set backend server url.
How to config jenkins environment?
Directlly write it into shell is a way.Another way is set global environment.
Jenkins has some other config but now we don't need too much.
Thanks for reading!