How it works...

We've configured our Jenkins job, now let's test it. I'm going to modify a simple file to be sure the Jenkins works properly.

At this point (if you followed the first recipe), you must stop the PM2 server with the command "npm run stop" and then remove the production directory that we cloned before, to avoid problems with the Jenkins job.

Let's modify our Home component; I'll add an extra text (Jenkins):

  import React from 'react';
import styles from './Home.scss';

const Home = props => (
<h1 className={styles.Home}>Hello {props.name || 'World'} (Jenkins)</h1>
);

export default Home;
File: src/client/home/index.jsx

After that, you need to commit and push to master. Now go to Jenkins, select your job, and click on Build Now:

After that, click on the latest build (in my case it's #5 because I did some tests before, but for you, it will be #1):

In the build, you will see who (user) started the build and which is the revision (last commit of master) that is building. If you want to see the Console Output, you can click on that option on the left menu:

If you look at the Console Output, you will see tons of commands:

Every time we run a new build, Jenkins will fetch the latest changes of the repository:

    git config remote.origin.url https://github.com/csantany/production.git

Then will get the last commit of the master:

    git rev-parse refs/remotes/origin/master^{commit}

And finally, it will execute the commands we specified on the Post build task:

    npm install && npm run start-production

If everything works fine, you should see Finished: SUCCESS at the end of the output:

Now wait 30 seconds or 1 minute and then visit your production site (in my case http://142.93.28.244/ you will see the new changes:

If you're wondering where the files are stored, you can see them at /var/lib/jenkins/workspace/<your_jenkins_job_name>.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset