How to Use Travis CI with Java on GitHub

Time:2021-6-14

1. Build

  • Sign in to your user Github account and fork this repo (https://github.com/kreattang/…
  • Go to Travis-ci.com and Sign in with GitHub account
    How to Use Travis CI with Java on GitHub
  • Accept the Authorization of Travis CI
  • Click on your profile picture in the top right of your Travis Dashboard, click Settings

How to Use Travis CI with Java on GitHub

  • Select the repo you want to use with Travis CI. If repo cannot be found, click Sync account

How to Use Travis CI with Java on GitHub

  • Back to Github. Create a .travis.yml file and add the following content(to tell Travis CI what to do), commit and push the changes to the root directory of your repo

    # Building a Java project
    language: java
    
    # We can specify a list of JDKs to be used for testing
    jdk:
     - openjdk11
  • Back to Travis CI. Click your repo and you will find it start build by Travis CI

How to Use Travis CI with Java on GitHub

  • If the build is successful, you will see a green badge as follows.

How to Use Travis CI with Java on GitHub

  • Create the README.md badge(copy the markdown code from Travis CI and paste in the top line of readme.md)

    Travis CI => select your repository => click the build status image => select FORMAT as Markdown => Copy the code of RESULT => paste in the top line of readme.md

How to Use Travis CI with Java on GitHub

  • You will see a badge like this in your repo of Github

How to Use Travis CI with Java on GitHub

2. Test

This repo also integrates with Codecov to generate reports.

How to Use Travis CI with Java on GitHub

  • Accept the authorization of Codecov and add your repository
  • Add the following code in the end of .travis.yml file. This is to enable CodeCov’s coverage.
    If a build is successful, the code is submitted for coverage analysis

    after_success:
    - bash <(curl -s https://codecov.io/bash)
  • Commit and push the changes to your repo, which will trigger a new build in Travis CI
  • Create the README.md badge of coverage

    Codecov =>select your repository => Setting => Bedge => Copy the contect of Markdown => paste in readme.md

  • You will see the badge like this in your repo

How to Use Travis CI with Java on GitHub

3.Deploy

  • Travis CI can help you release to Github after a success build. You will need to provide a Github personal access token(Tutorial: https://docs.github.com/en/gi…
  • Now that we have a token go to the project you want to use it with on Travis CI. Then on your project page, go to More options => Settings

How to Use Travis CI with Java on GitHub

  • In the Environment Variables section, add variable named GITHUB_TOKEN and use the generated token from Github in previous step

How to Use Travis CI with Java on GitHub

deploy:
  provider: releases
  file_glob: true
  skip_cleanup: true
  api_key: $GITHUB_TOKEN
  file:
    - .travis.yml
  on:
    tags: true
    branch: tag
    repo: <your_github_username>/<your_repo_name>
  • Commit and push to trigger a Travis CI build. If the build is successful, you will see .travis.yml in the Releases section of your repo like this

How to Use Travis CI with Java on GitHub

4. Trigger a failed build and notify build result

  • Travis CI can notify you about your build results through email, IRC, chat or custom webhooks (https://docs.travis-ci.com/us…
  • Add the following to your .travis.yml, which will send the build result to your Email

    notifications:
     email:
    - [email protected](replace by your e-mail)
  • Modify the line 61 of trityp.java(src/main/…/trityp.java) as follows

    triOut = triOut + 2;

How to Use Travis CI with Java on GitHub

  • Commit and push to trigger a Travis CI build. As expected, this build will failed and you will receive an Email like this

How to Use Travis CI with Java on GitHub