From 8e4e80918e6e2ce79f369638716884d087969ab3 Mon Sep 17 00:00:00 2001 From: houmingtao Date: Fri, 5 Oct 2018 23:23:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A2=9D=E5=A4=96=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java/build/maven_docker/Dockerfile | 1 + java/build/maven_docker/README.md | 1 + java/build/maven_docker/builder.go | 30 +++++++++++++++++++++++++++--- java/build/maven_docker/main.go | 1 + 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/java/build/maven_docker/Dockerfile b/java/build/maven_docker/Dockerfile index 66136e3..8963526 100644 --- a/java/build/maven_docker/Dockerfile +++ b/java/build/maven_docker/Dockerfile @@ -29,6 +29,7 @@ LABEL TencentHubComponent='{\ {"name": "M2_SETTINGS_XML", "desc": "非必填,$user/.m2/setting.xml配置文件内容,默认使用maven的全局配置"},\ {"name": "GOALS", "desc": "非必填,maven 构建目标, 默认是package"},\ {"name": "POM_PATH", "desc": "非必填,pom 文件相对路径, 默认`./pom.xml`"},\ + {"name": "EXT_COMMAND", "desc": "非必填,GOALS之外的命令, 默认不执行"},\ {"name": "_WORKFLOW_FLAG_HUB_TOKEN", "default": "true", "desc": "非必填, 若为真, 工作流将根据用户名和密码自动填充HUB_USER和HUB_TOKEN"}\ ]\ }' diff --git a/java/build/maven_docker/README.md b/java/build/maven_docker/README.md index 3088754..9bcb3fa 100644 --- a/java/build/maven_docker/README.md +++ b/java/build/maven_docker/README.md @@ -9,6 +9,7 @@ - `M2_SETTINGS_XML` 非必填,`$user/.m2/setting.xml`配置文件内容,默认使用maven的全局配置 - `GOALS` 非必填,maven 构建目标, 默认是`package` - `POM_PATH` 非必填,pom 文件相对路径, 默认`./pom.xml` +- `EXT_COMMAND` 非必填,GOALS之外的命令, 默认不执行 ### Tag列表及其Dockerfile链接 diff --git a/java/build/maven_docker/builder.go b/java/build/maven_docker/builder.go index f20960a..f223956 100644 --- a/java/build/maven_docker/builder.go +++ b/java/build/maven_docker/builder.go @@ -6,6 +6,7 @@ import ( "os/exec" "path/filepath" "strings" + "bytes" ) const baseSpace = "/root/src" @@ -21,14 +22,16 @@ type Builder struct { HubUser string HubToken string M2SettingXML string - + ExtCommand string projectName string } // NewBuilder is func NewBuilder(envs map[string]string) (*Builder, error) { b := &Builder{} - + if envs["GIT_CLONE_URL"] != "" { + b.ExtCommand = envs["EXT_COMMAND"] + } if envs["GIT_CLONE_URL"] != "" { b.GitCloneURL = envs["GIT_CLONE_URL"] b.GitRef = envs["GIT_REF"] @@ -82,6 +85,10 @@ func (b *Builder) run() error { return err } + if err := b.execCommand(); err != nil { + return err + } + // if err := b.handleArtifacts(); err != nil { // return err // } @@ -152,6 +159,23 @@ func (b *Builder) gitReset() error { return nil } +func (b *Builder) execCommand() error{ + if(b.ExtCommand == ""){ + return nil + } + fmt.Printf("exec:%s", b.ExtCommand) + cmd := exec.Command("/bin/bash", "-c", b.ExtCommand) + var out bytes.Buffer + + cmd.Stdout = &out + err := cmd.Run() + if err != nil { + fmt.Println("exec:%s", b.ExtCommand, "Failed:", err) + } + fmt.Printf("%s", out.String()) + return err +} + type CMD struct { Command []string // cmd with args WorkDir string @@ -172,4 +196,4 @@ func (c CMD) Run() (string, error) { } return result, err -} +} \ No newline at end of file diff --git a/java/build/maven_docker/main.go b/java/build/maven_docker/main.go index 842e7c9..267551e 100644 --- a/java/build/maven_docker/main.go +++ b/java/build/maven_docker/main.go @@ -13,6 +13,7 @@ var envList = []string{ "GOALS", "POM_PATH", + "EXT_COMMAND", "M2_SETTINGS_XML", }