Jenkins is an award-winning, cross-platform, continuous integration and continuous delivery application that increases your productivity. Use Jenkins to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by providing powerful ways to define your build pipelines and integrating with a large number of testing and deployment technologies.

We should follow the below steps to configure the Jenkins job,

1. Create a new job

Enter your job name and Choose the Freestyle project option (If your project eligible with other options, you can choose that)

2. By default, Job configuration page don’t have the Git option in Source Code Management. So, we have to install Git plugin.

Go to plugin page and type “Git plugin” in search box, you will get Git plugin. Choose that plugin and click Download now and Install after restart button.

3. If you already installed Git in your server, omit this step,

sudo yum install git

4. After installing Git, we have to mention that Git path in Jenkins->Configuration page

Enter your git path in Path to git executable field. Example path /usr/bin/git

If you don’t know path of Git, type the below comment to get path.

which git

5. After installing Git plugin, we have to configure job with Git.

  • Now, we will get Git option in Source Code Management in Job configuration page.
  • Enter Repository URL, If you are using bitbucket use URL like below example.
  • Original Repository URL: https://username@bitbucket.org/username/project_name.git
  • Changed Repository URL: https://bitbucket.org/username/project_name.git
  • Then, give credential of Git and mention your project branch for build, example: */master

6. For publish build to server, have to install Publish SSH plugin

Go to plugin page and type “Publish Over SSH” in search box, you will get Publish SSH plugin. Choose that plugin and click Download now and Install after restart button.

7. After installing Publish SSH plugin, we have to add SSH server details in Jenkins->Configuration page

8. Under Publish over SSH, give your server SSH private key and give Passphrase if you have or leave it empty and Save it.

10. After configuration of SSH server, go to the Job configuration page. In Build Environment, choose “Send files or execute commands over SSH after the build runs”

11. Choose SSH server name, in SSH publishers

12. For upload files to SSH, enter ** in Source files field

13. If you want to avoid some files to upload, Click advanced button and add files with comma(,) operator. Example: .env,config/database.php

14. Finally save it

Now, we have been completed the Jenkins job configuration.

Go to the home page and click Build button. If you got this error, ERROR: Exception when publishing, exception message [Permission denied]. Give permission to /var/www/html/project_path.

Please refer below screen shots for more clarification.