1. Install the Jenkins

IO /zh/doc/book…

2. Configure the SSH key for Jenkins mirroring

Assuming you have successfully logged in to Jenkins, you can see the following screen

Ok, now let’s go to the mirror command line and generate the SSH key

  1. View the ID of the current running mirror
$ docker ps
Copy the code

docker exec-it Your mirror ID /bin/bashCopy the code

Git and password-free login to a remote server

$ cdSSH $SSH -keygen -t rsa -c your email address $cat id_rsa.pubCopy the code

After the last command, you can see the key string

Then we went to Github and the service providers (such as Conscience Cloud and Tao Cloud) to configure SSH, which I won’t go into. I am a pickled cabbage fish

3. Configure Jenkins’ Github hook

  1. Enter the main screenSystem management
  2. Enter system Settings
  3. Drop down to see the Github configuration area, where the Github plug-in is automatically installed during the initial initialization, and can be installed in the plug-inGitHub plugin

    Click after credentialsAddButton, add credentials, is the account password, do well after the click connection test, success can be

  4. Then click belowAdvance

    Check to generate hook

  5. Go to github project and configure hook

4. Create a task

shell

5. Now look at the shell in detail

#! /bin/shSsh-tt Remote server username @REMOTE server IP address << remotesshcd /home/tlgc_server_api
/bin/git pull
npm run stop
npm run start
exit  
remotessh 
Copy the code
  • The first sentence indicates that this is a shell script
  • Second sentence, prevent error reportingPseudo-terminal will not be allocated because stdin is not a terminal.So givesshadd-ttParameter required in order to be able to execute commands on remote machines<< remotesshNote that the last two sentences are used to exit the remote machine, otherwise, the task will be impossible to cure.
  • The fourth sentence is used heregitThe full path to, written earliercronI’ve seen it before, executionbash, need to use/bin/bash, execute heregitCommand, also requires the full path/bin/gitI used it last nightgit“And then without adding the last two sentences, the task has been stuck there, stuck all night…

6. Test it out at the end. Perfect

7. To sum up

The feeling is ok, although it does not use Jenkins’ other good features, but suitable for myself is the best automated deployment experience so far

  • github + docker + dockerhub
  • github + docker + daocloud
  • github + jenkins + ssh
  • gitlab runner

Daocloud I used to find daoCloud convenient, now I’m developing it with Jenkins, it depends on personal taste