Jenkins is a popular automation tool that provides an alternative to CI/CD processes. It automates tasks such as building, testing, and deploying applications. In this article, we will delve into how to use Jenkins to automate a Spring Boot application.
Navigate to the directory containing the Dockerfile and run the command docker build -t [imageName] . to create the image. Use docker images to confirm its creation. Go to the root directory of our Spring Boot application and create a docker-compose file. Include the created image and execute the command docker compose up -d.
After starting the container, use the docker container ls command for verification. Access the Jenkins setup screen. Since we're working locally, we go to localhost:8080. Obtain the password by running the docker logs -f [container_name] command. The password will be displayed in yellow. Paste the password and proceed. Select the "Install Suggested Plugins" option. Once the installation process completes, create an administrator account. Configure the Jenkins application URL. After successful configuration, install necessary plugins. Navigate to "Manage Jenkins," then "Plugins," and then "Available Plugins" to install the following:
[Plugin list]
Go to "Dashboard," then "New Item," and choose "Freestyle Project." Configure the GitHub settings. Among the installed plugins, we have "Generic Webhook Trigger." This plugin allows our project to be triggered whenever a commit is made. If you wish to use it, check the corresponding checkbox. Add a build step and select "Execute Shell." Enter the following commands:
docker build --rm -t [buildName] . docker run --rm -d -p [Port:Port] --name [tagName] [buildName]
Go to the project page and click "Build Now." Observe the build process under the "Build" tab. To trigger Jenkins configurations after each commit, add a webhook to the GitHub repository. Navigate to github.com/[username]/[projectName]/settings/hooks, add a webhook, and include the Payload URL. Save the changes.
0 comments:
Post a Comment