Deploy 01: How to use jenkins?

49 阅读1分钟

Using TXcloud or AliCloud is terrible because I need to access github and I don't want to config Magic or Proxy on server.So I choose EC2 server then downloaded docker then 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.

image.png

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😂)

image.png

Here is some import config:

image.png

image.png

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.

image.png

Now this project is created.Let us have a test.

image.png

image.png

Safe and sound.But we need after git push it will trigger. Here is a important step:

image.png

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.

image.png

Add a little feature

How about we let jenkins run our js code?Change build step and run shell:

image.png

Just click Build Now to trigger shell.

image.png

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.

image.png

After install a node version we need to apply it into our jenkins project.

image.png

Rebuild. Success!

image.png

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.

image.png

image.png

How to config jenkins environment?

image.png

Directlly write it into shell is a way.Another way is set global environment.

image.png

Jenkins has some other config but now we don't need too much.


Thanks for reading!