-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
99 lines (82 loc) · 2.74 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"io/ioutil"
"os"
"runtime"
"time"
"github.com/ci-plugins/golang-plugin-sdk/api"
"github.com/ci-plugins/golang-plugin-sdk/log"
"github.com/ci-plugins/plugin-demo-golang/translation"
)
//go:generate i18ngenerator i18n ./translation/translation.go
type greetingParam struct {
UserName string `json:"userName"`
Greeting string `json:"greeting"`
}
func (a *greetingParam) String() string {
return fmt.Sprintf("userName: %v, greeting: %v", a.UserName, a.Greeting)
}
func main() {
runtime.GOMAXPROCS(4)
log.Info("atom-demo-glang starts")
defer func() {
if err := recover(); err != nil {
log.Error("panic: ", err)
api.FinishBuild(api.StatusError, "panic occurs")
}
}()
api.InitI18n(translation.Translations, api.GetRuntimeLanguage())
msg, err := api.Localize("input.desc.label")
if err != nil {
log.Error(err)
}
log.Info(msg)
helloBuild()
}
func helloBuild() {
// 获取单个输入参数
userName := api.GetInputParam("userName")
log.Info("userName: ", userName)
// 打屏
log.Info("\nBuildInfo:")
log.Info("Project Name: ", api.GetProjectDisplayName())
log.Info("Pipeline Id: ", api.GetPipelineId())
log.Info("Pipeline Name: ", api.GetPipelineName())
log.Info("Pipeline Version: ", api.GetPipelineVersion())
log.Info("Build Id: ", api.GetPipelineBuildId())
log.Info("Build Num: ", api.GetPipelineBuildNumber())
log.Info("Start Type: ", api.GetPipelineStartType())
log.Info("Start UserId: ", api.GetPipelineStartUserId())
log.Info("Start UserName: ", api.GetPipelineStartUserName())
log.Info("Start Time: ", api.GetPipelineStartTimeMills())
log.Info("Workspace: ", api.GetWorkspace())
// 输入参数解析到对象
paramData := new(greetingParam)
api.LoadInputParam(paramData)
log.Info(fmt.Sprintf("\n%v,%v\n", paramData.Greeting, paramData.UserName))
// 业务逻辑
log.Info("start build")
build()
time.Sleep(2 * time.Second)
// 输出
// 字符串输出
strData := api.NewStringData("test")
api.AddOutputData("strData_01", strData)
// 文件归档输出
artifactData := api.NewArtifactData()
artifactData.AddArtifact("result.dat")
api.AddOutputData("artifactData_02", artifactData)
// 报告输出
reportData := api.NewReportData("label_01", api.GetWorkspace()+"/report", "report.htm")
api.AddOutputData("report_01", reportData)
api.WriteOutput()
log.Info("build done")
}
func build() {
log.Info("write result.dat")
ioutil.WriteFile(api.GetWorkspace()+"/result.dat", []byte("content"), 0644)
log.Info("write report.htm")
os.Mkdir(api.GetWorkspace()+"/report", os.ModePerm)
ioutil.WriteFile(api.GetWorkspace()+"/report/report.htm", []byte("<html><head><title>Report</title></head><body><H1>This is a Report</H1></body></html>"), 0644)
}