Register a travis cl account
Go to the official website of Travis CI https://travis-ci.org to register and log in, generally use github to authorize to log in, click Sign In
Create a SpringBoot or Maven web project and submit to GitHub
Here I create a springboot project
Import spring web and junit coordinates
<!--spring web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
Write a controller
@RestController public class HelloController { @RequestMapping("/") public String hello() { return "hello world! Travis CI!"; } }
Springboot test class:
import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest class TestTravisSpringbootApplicationTests { @Test void contextLoads() { System.out.println("This is a simple test, and you pass it."); } }
Then add the README file for the project online, otherwise the next step
Build the github project on travis ci official website
Click the "+" sign here
Find or search our items
Open button to the right of the project
Add [.travis.yml] file under the project root directory
This step is created under the github official website project, click create new file
Can also be created directly locally:
language: java
install: mvn install
After pushing the .travis.yml file, you can see the project changes on the travis ci official website
Automatic deployment
Now that Travis can automatically execute the build process based on our submission, the next step is to deploy to a remote server. Travis provided
after_success
to achieve this step.However, there is one thing that needs to be dealt with before this, because we want to deploy to the server, it is bound to require Travis to log in to the remote server, because it is an open source project, how should we solve the login password problem?
encryption