Skip to content

Commit

Permalink
添加额外命令的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
julywind committed Oct 5, 2018
1 parent 5211f38 commit 8e4e809
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions java/build/maven_docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"}\
]\
}'
1 change: 1 addition & 0 deletions java/build/maven_docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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链接

Expand Down
30 changes: 27 additions & 3 deletions java/build/maven_docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"bytes"
)

const baseSpace = "/root/src"
Expand All @@ -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"]
Expand Down Expand Up @@ -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
// }
Expand Down Expand Up @@ -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
Expand All @@ -172,4 +196,4 @@ func (c CMD) Run() (string, error) {
}

return result, err
}
}
1 change: 1 addition & 0 deletions java/build/maven_docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var envList = []string{

"GOALS",
"POM_PATH",
"EXT_COMMAND",
"M2_SETTINGS_XML",
}

Expand Down

0 comments on commit 8e4e809

Please sign in to comment.