Deploy a Liferay 7/DXP workspace project with Jenkins
Our project is a Liferay Workspace Project and lives in git. The test environment is on a remote server. So, our goal is to
- run the build with a slave on the remote server
- define some parameters like the branch
- checkout the project from git
- build the project with gradle
- run tests
- deploy the modules
- notify with email in case of failure
- notify with mattermost
- publish junit results
You have to preinstall
- the git plugin
- the gradle plugin
- the mattermost notification plugin
Let us begin...
1. Configure jenkins & plugins
- Configure Slave
You have to go to Jenkins
> Manage Jenkins
> Manage Nodes
> New Node
Follow the wizard and create a new node on the remote server.
- Configure git
You have to go to Jenkins
> Manage Jenkins
> Global Tool Configuration
> Git
> Add Git
> jGit
2. Create a parametrized job
It will need the Git Parameter Plug-In.
You have to go to Jenkins
> New Item
Enter the jobs name and choose Freestyle Project
. This will create a new job. On the screen that appears you can configure the job you just created. Choose General
> This project is parameterized
> Add Parameter
> Git Parameter
. Give a name to the parameter and a description if you want to. The name is the variable name you will use later for the checkout. An example name is BUILD_SELECTOR
. Choose ``.
Then, press Add paramter
and choose String parameter
. In Name
type LIFERAY_HOME
and in Default Value
type the path to the liferay portal in your remote server.
Also, choose Restrict where this project can be run
and then type the name of the slave you created in step 1.
3. Checkout source code from git
Go to Source Code Management
> Git
Type the Repository URL
and choose or add credentials if needed. Also, if you have a repository browser like gitlab, you can choose it in Repository browser
and configure it. This will create links from the reports to your repository browser. In Branches to build
type ${BUILD_SELECTOR}
, if that is the parameter name from step 2. In Additional Behaviours
choose Clean before checkout
.
4. Build project
Go to Build
> Add build step
> Invoke Gradle script
> Use Gradle Wrapper
. Choose Use Gradle Wrapper
. In Switches
type -p modules -Pliferay.workspace.home.dir=${LIFERAY_HOME}
5. Run tests
Go to Build
> Invoke Gradle script
> Tasks
and type test
6. Deploy modules
Go to Build
> Invoke Gradle script
> Tasks
and type on a new line deploy
7. Notify with email
Go to Post-build Actions
> Add post-build action
> Add e-mail notification
In Recipients
type the emails comma seperated.
8. Notify with mattermost
Go to Post-build Actions
> Add post-build action
> Mattermost Notifications
Select the wanted notifications. Press Advanced...
. Make also your choices here. In Endpoint
type the hoot url from mattermost and in Project Channel
type the name of the channel you want to sent the notification.
9. Publish junit results
Go to Post-build Actions
> Add post-build action
> Publish JUnit test result report
In Test report XMLs
type modules/**/TEST*.xml
The end
Now, press Save
and run you job. Choose the branch and start the job.
