Giter Club home page Giter Club logo

jenkins_deploy_checklist's Introduction

Automatic Deployments with Jenkins

Keys

  1. Create a ssh key for jenkins to use: ssh-keygen -t rsa -b 4096 -C "[email protected]" and create a deployer_rsa and deployer_rsa.pub file
  2. Go to Github (or Github enterprise)
  3. Go to your repository and click on Settings, then on the left tab look for Deploy Keys
  4. Create a new key and copy the contents of deployer_rsa.pub into the field.

Jenkins configuration

  1. Install the github plugin in jenkins: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin (it’s usually part of it)
  2. Let’s add the private key to jenkins. In Jenkins, on the left click on Credentials->System then click Global Credentials (unrestricted) and click Add Credentials
  3. For Kind: set it to SSH Username with private key
  4. Private Key: enter directly and copy the contents of deployer_rsa into the Key field and click ok.
  5. Create a new task, under the Github project you can enter the URL to the project. This is just a link
  6. Under Source Code Management , select git and put the repository URL (such as [email protected]:cybersonic/jenkins_deploy.git )
  7. It might refresh and say: 
 Failed to connect to repository : Command "git ls-remote -h [email protected]:cybersonic/jenkins_deploy.git HEAD" returned status code 128:
stdout: 
stderr: Host key verification failed.
  8. Under credentials select Jenkins, this should clear the error as we are now using that credential
  9. Set the branches to build, for example */master
  10. under Build Triggers now you can do Build when a change is pushed to Github.
  11. To enable this from github end we have to go back to our project in GitHub and go to Settings, Integrations & services. There click Add Service and find the Jenkins (Github plugin) service. When it asks you for the url enter the name of your server with “github-webhook/“ at the end, for example: “http://jenkins.markdrew.pagekite.me/github-webhook/“ and save it.
  12. Now we can test if it automatically runs by changing a file in the repo.

Deploying the code

So far we are now just checking out the code to the Jenkins workspace for this task. You should be able to see your code in the Workspace folder of the task in Jenkins. What we will do now is actually sync it from the workspace folder to another buy telling jenkins to run a build script

  1. Go to the root of Jenkins and click Manage Jenkins and Global Tool Configuration.
  2. Under Ant, click Add Ant, and give it a name like Global Ant installation
  3. Make sure that Install automatically is ticked and click Save
  4. In the task, click Configure and under the Build and Add build step
  5. Select Invoke Ant
  6. Select the Ant Version we defined (Global Ant Installation)
  7. Ignore the Targets for the moment, you can keep it clear. What this will do is call the build.xml file with the default target. We will want to pass some variables to this in a bit but let's let it run to test.
  8. Using the ant file in this project it should sync the files from workspace/source_dir to workspace/destination_dir

The build script in this project is designed to be customizable, so you can set which files get moved where, by setting the destination and source variables in your Jenkins task.

  1. Edit the task configuration again. And go down to the build section
  2. click on the Advanced... to expand everything
  3. edit the Properties field and click on the down arrow and add the following, changing the destination path for what you need:
souce=.
destination=/var/jenkins_home/temp

This should now synch the source directory with the destination directory

jenkins_deploy_checklist's People

Contributors

cybersonic avatar nolanerck avatar

Stargazers

 avatar

Watchers

 avatar Matt Gifford avatar James Allen avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.