Build and test Java + Gradle applications with Wercker

Although my work record aspect is strong, I created the procedure for Wercker based on the actual work record. Since I am new to CI itself, there may be some mistakes. In that case, please point out.

Overview

This is the procedure for automatic build and automatic test with Wercker in the GitHub repository of Java application using Gradle. I've tested public repositories here, but I might try private repositories and add results.

Wercker

URL

https://app.wercker.com/

Overview

Wercker, reading is worker. Recently acquired by Oracle. You can use the private repository for free. You can build a build environment using Docker.

table of contents

  1. Wercker sign-in
  2. Register your GitHub repository with Wercker
  3. Wercker.yml created, pushed to GitHub repository, automated build, automated test works
  4. Set wercker.yml to pass the build
  5. Confirm that if the JUnit test on Gradle fails, the build will also fail on Wercker.
  6. Force Wercker check on GitHub repository and reject merge if test NG

Wercker sign-in

  1. Access Wercker
  2. You can log in with your GitHub account

Register your GitHub repository with Wercker

  1. Click the Wercker Create your first application button
  2. Select User & SCM screen
    1. Select a user from the doropdown begin.* --Wercker account is displayed, select the account to use
    2. Select SCM --Supported by GitHub, Bitbucket, GitLab ――This article uses GitHub, so select GitHub
  3. Select Repository screen
  4. Select the GitHub repository to add to Wercker --Only repositories with admin privileges are displayed (should, read the Wercker documentation, but point out if it's wrong)
  5. Setup SSH Key screen
    • wercker will check out the code without using an SSH key --Wercker checks out the target repository without an SSH key --Select this because it is recommended
    • Add the deploy key to the selected repository for me --Register SSH key to access the repository --Deprecated, probably because you don't easily pass repository operation privileges
  6. Review screen
  7. Make sure that the settings are as you selected
    1. Make my app public --If checked, you will be able to publish the deployment information when you click the badge that appears later. --Do not check if not needed
  8. Application addition on Wercker is completed

Create wercker.yml and push it to your GitHub repository

  1. From the repository registration completion screen, the yml addition screen is open as it is
  2. Select Java Gradle from the select box labeled Select a language
  3. The contents of wercker.yml will be displayed, so copy it to the clipboard.
  4. Create a file with the copied contents as a wercker.yml file directly under the root of the repository. --Java version may need to be changed accordingly --Changed from box: openjdk: 8-jdk to box: openjdk: 10.0.1-jdk --box is synonymous with pull in Dockerfile -Refer to [openjdk official DockerHub](https://hub.docker.com/_/openjdk/) and described the `` `10.0.1-jdk part.
  5. Push wercker.yml to the repository
  6. Catch the push and automatically run on Wercker
  7. Success or error --In my work, I failed with an error during the build phase of wercker. --There was a log that Gradle 4.2 was specified at the time of execution, but since Gradle 4.2 does not support Java 10, an error occurs. --Since it was developed with Gradle 4.8, the Gradle version used is low.
  8. Explain the resolution of the error in the matter

Wercker default wercker.yml contents

# This references an OpenJDK container from the
# Docker Hub https://hub.docker.com/_/openjdk/
# Read more about containers on our dev center
# http://devcenter.wercker.com/docs/containers/index.html
box: openjdk:8-jdk

# This is the build pipeline. Pipelines are the core of wercker
# Read more about pipelines on our dev center
# http://devcenter.wercker.com/docs/pipelines/index.html
build:
    # Steps make up the actions in your pipeline
    # Read more about steps on our dev center:
    # http://devcenter.wercker.com/docs/steps/index.html
  steps:
    # https://github.com/wercker/step-gradle
    - java/gradle:
      task: build
      cache_project_cache: true

Set wercker.yml to allow the build to pass

Countermeasures

  1. If you set version: in the build item of wercker.yml, java / gradle, you should be able to make it any version.
  1. If you use gradle wrapper instead of relying on java / gradle of wercker.yml, you should be able to execute it with any version. --Changed wercker.yml according to Wercker Official Guide --Since it is reflected in the final content, see below for details. --Deleted the originally written build step item --Run gradlew bootRun on dev item --Run gradlew build on build item
  1. Add gradle-wrapper.jar to the repository so gradlew can run --All .jars were uncommitted with .gitignore --The class could not be found because there is no gradle-wrapper.jar in the gradle / wrapper directory directly under the root directory of the repository. --Added ! Gradle-wrapper.jar to .gitignore and added gradle-wrapper.jar to commit target --It is also a necessary jar for those who do not install gradle and run it with gradlew, so it is okay to make it a repository management target
  2. Successful build on Wercker

Final wercker.yml

# This references an OpenJDK container from the
# Docker Hub https://hub.docker.com/_/openjdk/
# Read more about containers on our dev center
# http://devcenter.wercker.com/docs/containers/index.html
box: openjdk:10.0.1-jdk

# defining the dev pipeline
dev:
  steps:
    # A step that executes `gradle bootRun` command
    - script:
      name: run gradle
      code: |
        ./gradlew bootRun

# Build definition
build:
  # The steps that will be executed on build
  steps:
    # A step that executes `gradle build` command
    - script:
        name: run gradle
        code: |
          ./gradlew --full-stacktrace -q --project-cache-dir=$WERCKER_CACHE_DIR build

Confirm that if the JUnit test on Gradle fails, the build will also fail on Wercker

  1. Dare to change the test code so that NG appears in the test class
  2. Commit and push the code containing the NG test to the GitHub repository
  3. Confirm that the build fails on Wercker ――I actually tried it and confirmed that the build phase failed.

Force Wercker check on GitHub repository and reject merge if test NG

  1. Open Settings in the GitHub repository
  2. Open Branches
  3. Select and open the master branch
  4. Check Require status checks to pass before merging
  5. Check the wercker / build item
  6. Subsequent pull requests to master cannot be merged without a successful Wercker build

Finally

So far, you can catch the push to GitHub on Wercker and check whether the build (test performed at the same time as the build) succeeds or fails automatically. There are still many things that can be done by setting the workflow, so I plan to leave them as a separate article if I try again.

bonus

Wercker Developer Documentation Mechanism of Wercker, how to make original box and step

Recommended Posts

Build and test Java + Gradle applications with Wercker
CICS-Run Java applications-(3) Build management with Gradle
Build Java with Wercker
Build a Java project with Gradle
Monitor Java applications with jolokia and hawtio
CICS-Run Java applications-(2) Build management with Maven
Java automated test implementation with JUnit 5 + Gradle
Integration Test with Gradle
First gradle build (Java)
Build an E2E test environment with Selenium (Java)
Using Gradle with VS Code, build Java → run
Compile with Java 6 and test with Java 11 while running Maven on Java 8
Check coverage with Codecov in Java + Gradle + Wercker configuration
Java multi-project creation with Gradle
Remote debugging with Gradle test
Use java with MSYS and Cygwin
Install Java and Tomcat with Ansible
Output test coverage with clover + gradle
Use JDBC with Java and Scala.
Java build with mac vs code
Output PDF and TIFF with Java 8
[Java] Test private methods with JUnit
Copy and paste test with RSpec
Encrypt with Java and decrypt with C #
Hello world in Java and Gradle
Spring Boot gradle build with Docker
[Gradle] Build a Java project with a configuration different from the convention
Easily convert Java application to Docker container with Jib ~ Build with gradle and register in local repository
Build a Windows application test environment with Selenium Grid, Appium, and Windows Application Driver
[Java] Create an executable module with Gradle
Beginners create web applications with Java and MySQL (adding at any time)
Build and manage RStudio environment with Docker-compose
Link Java and C ++ code with SWIG
Java EE test (CDI / interceptor) with Arquillian
Let's try WebSocket with Java and javascript!
[Java] Reading and writing files with OpenCSV
Build DNS server with CentOS8 and bind
Build OpenCV with Java Wrapper on Ubuntu 18.04
JUnit 5 gradle test fails with lombok annotation
Download JDK with Gradle and make JRE
Create Java applications with IBM Cloud Functions
Build Apache and Tomcat environment with Docker. By the way, Maven & Java cooperation
[Java] How to test for null with JUnit
[CircleCI 2.0] [Java] [Maven] [JUnit] Aggregate JUnit test results with CircleCI 2.0
Make SpringBoot1.5 + Gradle4.4 + Java8 + Docker environment compatible with Java11
Java management and STS (Eclipse) build path settings
[Gradle] Build operations often performed in Java projects
Java automated test implementation with JUnit 5 + Apache Maven
Static code analysis with Checkstyle in Java + Gradle
Run Scala applications with Spring Boot through Gradle
Try to link Ruby and Java with Dapr
Build Java environment and output hello world [Beginner]
JSON with Java and Jackson Part 2 XSS measures
Build Java x Spring x VSCode x Gradle on Docker (1)
Build Spring Boot project by environment with Gradle
Automate Java (Maven) project build with CircleCI + Orbs
How to build API with GraphQL and Rails
Prepare a scraping environment with Docker and Java
KMS) Envelope encryption with openssl and java decryption
Encrypt / decrypt with AES256 in PHP and Java
Mixin test cases with JUnit 5 and default methods