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