Bitbucket Pipelines 是Atlassian公司为Bitbucket Cloud产品添加的一个新功能, 它为托管在Bitbucket上的项目提供了一个良好的持续集成/交付的服务。html
目录 简介 前提 例子
Demo项目介绍 配置
工做流程
Overview
参考
申请 Bitbucket 帐号
Java 8
Gradle 2.6
Gitjava
准备一个小项目以便于更好的展现,用Vert.x建立一个简单的Restful web service, 另外再添加一个integration test,这里用的是rest-assured library,在我其它多篇文章都有介绍这个第三方库,专业作Restful API test, 你们能够参考。git
项目结构以下图web
##转载注明出处:http://www.cnblogs.com/wade-xu/p/6480319.html docker
App.javajson
1 package com.wadeshop.tutorial; 2 3 import java.time.LocalDateTime; 4 5 import io.vertx.core.Vertx; 6 import io.vertx.core.http.HttpServer; 7 8 public class App { 9 private HttpServer listen; 10 11 public static void main(String[] args) { 12 new App().run(); 13 14 } 15 16 public void run() { 17 listen = Vertx.vertx().createHttpServer() 18 .requestHandler(req -> req.response().putHeader("content-type", "application/json").end("{\"message\":\"" + LocalDateTime.now() + "\"}")).listen(8080, handler -> { 19 if (handler.succeeded()) { 20 System.out.println("server is running: http://localhost:8080/"); 21 } else { 22 System.err.println("server startup failed trying to listen on port 8080"); 23 } 24 }); 25 } 26 27 public void shutdown() { 28 if (listen != null) 29 listen.close(); 30 } 31 32 }
AppIntegrationTest.javaapp
package integration; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.notNullValue; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.wadeshop.tutorial.App; import io.restassured.http.ContentType; public class AppIntegrationTest { App app = new App(); @Before public void setup() { app.run(); } @After public void teardown() { app.shutdown(); } @Test public void shouldReturnValidDate() throws Exception { given().contentType(ContentType.JSON).when().get("http://localhost:8080/").then().body("message", notNullValue()); } }
此外,项目使用Gradle 做为Build 工具eclipse
[sts] ----------------------------------------------------- [sts] Starting Gradle build for the following tasks: [sts] :cleanEclipse [sts] :eclipse [sts] ----------------------------------------------------- :cleanEclipseClasspath :cleanEclipseJdt :cleanEclipseProject :cleanEclipse :eclipseClasspath :eclipseJdt :eclipseProject :eclipse BUILD SUCCESSFUL Total time: 1.345 secs [sts] ----------------------------------------------------- [sts] Build finished succesfully! [sts] Time taken: 0 min, 1 sec [sts] -----------------------------------------------------
A. 在Bitbucket 建repository, put your project to bucket工具
Step 1: Switch to your repository's directory测试
Step 2: Connect your existing repository to Bitbucket
B. 激活 Bitbucket Pipelines
接下来选择Java - Gradle 做为Template
配置yml 文件以下
bitbucket-pipelines.yml
# using gradle as build tool .. image: qlik/gradle pipelines: default: - step: script: - gradle --version - gradle test
注意 image: qlik/gradle 是一个安装了Java和Gradle的Docker镜像文件, 来自于DockerHub。
##转载注明出处:http://www.cnblogs.com/wade-xu/p/6480319.html
每当项目里有commit 被push 的时候, Pipelines会作以下步骤:
随便提交一个啥,而后看看结果, Successful了
点击看详细结果
##转载注明出处:http://www.cnblogs.com/wade-xu/p/6480319.html
接下来 故意把Test 断言改错 让case failed
Pipelines 也Failed了
详细Log