Skip to content

Commit 858bfda

Browse files
committed
添加额外命令的支持
1 parent 5211f38 commit 858bfda

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

java/build/maven_docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ LABEL TencentHubComponent='{\
2929
{"name": "M2_SETTINGS_XML", "desc": "非必填,$user/.m2/setting.xml配置文件内容,默认使用maven的全局配置"},\
3030
{"name": "GOALS", "desc": "非必填,maven 构建目标, 默认是package"},\
3131
{"name": "POM_PATH", "desc": "非必填,pom 文件相对路径, 默认`./pom.xml`"},\
32+
{"name": "EXT_COMMAND", "desc": "非必填,GOALS之外的命令, 默认不执行"},\
3233
{"name": "_WORKFLOW_FLAG_HUB_TOKEN", "default": "true", "desc": "非必填, 若为真, 工作流将根据用户名和密码自动填充HUB_USER和HUB_TOKEN"}\
3334
]\
3435
}'

java/build/maven_docker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- `M2_SETTINGS_XML` 非必填,`$user/.m2/setting.xml`配置文件内容,默认使用maven的全局配置
1010
- `GOALS` 非必填,maven 构建目标, 默认是`package`
1111
- `POM_PATH` 非必填,pom 文件相对路径, 默认`./pom.xml`
12+
- `EXT_COMMAND` 非必填,GOALS之外的命令, 默认不执行
1213

1314
### Tag列表及其Dockerfile链接
1415

java/build/maven_docker/builder.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/exec"
77
"path/filepath"
88
"strings"
9+
"bytes"
910
)
1011

1112
const baseSpace = "/root/src"
@@ -21,14 +22,16 @@ type Builder struct {
2122
HubUser string
2223
HubToken string
2324
M2SettingXML string
24-
25+
ExtCommand string
2526
projectName string
2627
}
2728

2829
// NewBuilder is
2930
func NewBuilder(envs map[string]string) (*Builder, error) {
3031
b := &Builder{}
31-
32+
if envs["GIT_CLONE_URL"] != "" {
33+
b.ExtCommand = envs["EXT_COMMAND"]
34+
}
3235
if envs["GIT_CLONE_URL"] != "" {
3336
b.GitCloneURL = envs["GIT_CLONE_URL"]
3437
b.GitRef = envs["GIT_REF"]
@@ -82,6 +85,10 @@ func (b *Builder) run() error {
8285
return err
8386
}
8487

88+
if err := b.execCommand(); err != nil {
89+
return err
90+
}
91+
8592
// if err := b.handleArtifacts(); err != nil {
8693
// return err
8794
// }
@@ -152,6 +159,23 @@ func (b *Builder) gitReset() error {
152159
return nil
153160
}
154161

162+
func (b *Builder) execCommand() error{
163+
if(b.ExtCommand == ""){
164+
return nil
165+
}
166+
fmt.Printf("exec:", b.ExtCommand)
167+
cmd := exec.Command("/bin/bash", "-c", b.ExtCommand)
168+
var out bytes.Buffer
169+
170+
cmd.Stdout = &out
171+
err := cmd.Run()
172+
if err != nil {
173+
fmt.Println("exec:", b.ExtCommand, "\nFailed:", err)
174+
}
175+
fmt.Printf(out.String())
176+
return err
177+
}
178+
155179
type CMD struct {
156180
Command []string // cmd with args
157181
WorkDir string
@@ -172,4 +196,4 @@ func (c CMD) Run() (string, error) {
172196
}
173197

174198
return result, err
175-
}
199+
}

java/build/maven_docker/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var envList = []string{
1313

1414
"GOALS",
1515
"POM_PATH",
16+
"EXT_COMMAND",
1617
"M2_SETTINGS_XML",
1718
}
1819

0 commit comments

Comments
 (0)