本文整理匯總了Golang中github.com/drone/drone-plugin-go/plugin.Param函數的典型用法代碼示例。如果您正苦於以下問題:Golang Param函數的具體用法?Golang Param怎麽用?Golang Param使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Param函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
v := struct {
Path string `json:"path"`
Depth int `json:"depth"`
}{}
c := new(plugin.Clone)
plugin.Param("clone", c)
plugin.Param("vargs", &v)
if err := plugin.Parse(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if v.Depth == 0 {
v.Depth = 50
}
if len(v.Path) != 0 {
c.Dir = filepath.Join("/drone/src", v.Path)
}
err := os.MkdirAll(c.Dir, 0777)
if err != nil {
fmt.Printf("Error creating directory %s. %s\n", c.Dir, err)
os.Exit(2)
}
// generate the .netrc file
if err := writeNetrc(c); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(3)
}
// write the rsa private key if provided
if err := writeKey(c); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(4)
}
var cmds []*exec.Cmd
if isPR(c) {
cmds = append(cmds, clone(c))
cmds = append(cmds, fetch(c))
cmds = append(cmds, checkoutHead(c))
} else {
cmds = append(cmds, cloneBranch(c))
cmds = append(cmds, checkoutSha(c))
}
for _, cmd := range cmds {
cmd.Dir = c.Dir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace(cmd)
err := cmd.Run()
if err != nil {
os.Exit(1)
}
}
}
示例2: main
func main() {
log.SetFlags(0)
plugin.Param("workspace", &workspace)
plugin.Param("build", &build)
plugin.Param("repo", &repo)
plugin.Param("vargs", &vargs)
plugin.MustParse()
sort.Strings(vargs.Gzip) // need for matchGzip
// context for all clients
ctx := context.Background()
// GitHub client
gts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: vargs.GitHubToken})
client.ghub = github.NewClient(oauth2.NewClient(ctx, gts))
// GCS client
auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
if err != nil {
fatalf("auth: %v", err)
}
tsrc := auth.TokenSource(ctx)
client.gcs, err = storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
if err != nil {
fatalf("storage client: %v", err)
}
// http client with service account authorization
client.http = oauth2.NewClient(ctx, tsrc)
run()
if ecode != 0 {
msg := fmt.Sprintf("exited with code %d", ecode)
updateStatus("error", msg, stagingURL)
}
os.Exit(ecode)
}
示例3: main
func main() {
c := new(plugin.Clone)
v := new(Rsync)
plugin.Param("clone", c)
plugin.Param("vargs", v)
plugin.Parse()
// write the rsa private key if provided
if err := writeKey(c); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// create the rsync command
rs := buildRsync(v)
rs.Dir = c.Dir
rs.Stderr = os.Stderr
rs.Stdout = os.Stdout
trace(rs)
err := rs.Run()
if err != nil {
os.Exit(1)
return
}
// and execute
// create remote command script
// and execute
}
示例4: main
func main() {
var repo = plugin.Repo{}
var build = plugin.Build{}
var vargs = struct {
Urls []string `json:"urls"`
}{}
plugin.Param("repo", &repo)
plugin.Param("build", &build)
plugin.Param("vargs", &vargs)
plugin.Parse()
// post build and repo data to webhook urls
data := struct {
Repo plugin.Repo `json:"repo"`
Build plugin.Build `json:"build"`
}{repo, build}
payload, _ := json.Marshal(&data)
for _, url := range vargs.Urls {
resp, _ := http.Post(url, "application/json", bytes.NewBuffer(payload))
resp.Body.Close()
}
}
示例5: main
func main() {
fmt.Println("starting drone-cowpoke...")
workspace := plugin.Workspace{}
vargs := Cowpoke{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
if len(vargs.Url) == 0 {
fmt.Println("no cowpoke url was specified")
os.Exit(1)
}
if vargs.Port == 0 {
fmt.Println("no cowpoke port was specified")
os.Exit(1)
}
fmt.Println("loading image data from", filepath.Join(workspace.Path, ".docker.json"))
image := GetImageName(filepath.Join(workspace.Path, ".docker.json"))
if len(image) <= 0 {
fmt.Println("image load failed from .docker.json")
os.Exit(1)
}
var cowpokeUrl = fmt.Sprintf("%s:%d/api/environment/", vargs.Url, vargs.Port)
fmt.Println("cowpoke url set to:", cowpokeUrl)
fmt.Println(".docker.json value being posted:", image)
ExecutePut(cowpokeUrl + url.QueryEscape(image))
fmt.Println("finished drone-cowpoke.")
}
示例6: main
func main() {
log.SetFlags(0)
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
script := strings.Join(vargs.Script, "\n")
if err := ioutil.WriteFile(scriptName, []byte(script), 0644); err != nil {
log.Fatalf("WriteFile(%q): %v", script, err)
}
c := vargs.Cmd
if c == "" {
c = defaultCmd
}
cmd := exec.Command(c, scriptName)
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = append(os.Environ(), vargs.Env...)
fmt.Println("$", strings.Join(cmd.Args, " "))
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}
示例7: main
func main() {
var repo = plugin.Repo{}
var build = plugin.Build{}
var vargs = struct {
Urls []string `json:"urls"`
}{}
plugin.Param("repo", &repo)
plugin.Param("build", &build)
plugin.Param("vargs", &vargs)
plugin.Parse()
// data structure
data := struct {
Repo plugin.Repo `json:"repo"`
Build plugin.Build `json:"build"`
}{repo, build}
// json payload that will be posted
payload, err := json.Marshal(&data)
if err != nil {
os.Exit(1)
}
// post payload to each url
for _, url := range vargs.Urls {
resp, err := http.Post(url, "application/json", bytes.NewBuffer(payload))
if err != nil {
os.Exit(1)
}
resp.Body.Close()
}
}
示例8: main
func main() {
fmt.Printf("Drone Terraform Plugin built from %s\n", buildCommit)
workspace := plugin.Workspace{}
vargs := terraform{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
if vargs.RoleARN != "" {
assumeRole(vargs.RoleARN)
}
var commands []*exec.Cmd
remote := vargs.Remote
if vargs.Cacert != "" {
commands = append(commands, installCaCert(vargs.Cacert))
}
if remote.Backend != "" {
commands = append(commands, deleteCache())
commands = append(commands, remoteConfigCommand(remote))
}
commands = append(commands, getModules())
commands = append(commands, planCommand(vargs.Vars, vargs.Parallelism))
if !vargs.Plan {
commands = append(commands, applyCommand(vargs.Parallelism))
}
commands = append(commands, deleteCache())
for _, c := range commands {
c.Env = os.Environ()
c.Dir = workspace.Path
if c.Dir == "" {
wd, err := os.Getwd()
if err == nil {
c.Dir = wd
}
}
if vargs.RootDir != "" {
c.Dir = c.Dir + "/" + vargs.RootDir
}
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if !vargs.Sensitive {
trace(c)
}
err := c.Run()
if err != nil {
fmt.Println("Error!")
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Command completed successfully")
}
}
示例9: main
func main() {
workspace := plugin.Workspace{}
vargs := S3{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
// skip if AWS key or SECRET are empty. A good example for this would
// be forks building a project. S3 might be configured in the source
// repo, but not in the fork
if len(vargs.Key) == 0 || len(vargs.Secret) == 0 {
return
}
// make sure a default region is set
if len(vargs.Region) == 0 {
vargs.Region = "us-east-1"
}
// make sure a default access is set
// let's be conservative and assume private
if len(vargs.Access) == 0 {
vargs.Access = "private"
}
// if the target starts with a "/" we need
// to remove it, otherwise we might adding
// a 3rd slash to s3://
if strings.HasPrefix(vargs.Target, "/") {
vargs.Target = vargs.Target[1:]
}
cmd := command(vargs)
cmd.Env = os.Environ()
if len(vargs.Key) > 0 {
cmd.Env = append(cmd.Env, "AWS_ACCESS_KEY_ID="+vargs.Key)
}
if len(vargs.Secret) > 0 {
cmd.Env = append(cmd.Env, "AWS_SECRET_ACCESS_KEY="+vargs.Secret)
}
cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace(cmd)
// run the command and exit if failed.
err := cmd.Run()
if err != nil {
os.Exit(1)
}
}
示例10: main
func main() {
var vargs = struct {
ReplicationControllers []string `json:replicationcontrollers`
Services []string `json:services`
ApiServer string `json:apiserver`
Token string `json:token`
Namespace string `json:namespace`
Debug string `json:debug`
Webhook string `json:webhook`
Source string `json:source`
WebHookToken string `json:webhook_token`
}{}
workspace := plugin.Workspace{}
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.Parse()
// Iterate over rcs and svcs
for _, rc := range vargs.ReplicationControllers {
artifact, err := readArtifactFromFile(workspace.Path, rc, vargs.ApiServer, vargs.Namespace)
if err != nil {
log.Panic(err)
return
}
if b, _ := existsArtifact(artifact, vargs.Token); b {
deleteArtifact(artifact, vargs.Token)
time.Sleep(time.Second * 5)
}
createArtifact(artifact, vargs.Token)
}
for _, rc := range vargs.Services {
artifact, err := readArtifactFromFile(workspace.Path, rc, vargs.ApiServer, vargs.Namespace)
if err != nil {
log.Panic(err)
return
}
createArtifact(artifact, vargs.Token)
}
wh := &WebHook{
Timestamp: makeTimestamp(),
Images: deployments,
Namespace: vargs.Namespace,
Source: vargs.Source,
Target: vargs.ApiServer,
Url: vargs.Webhook,
Token: vargs.WebHookToken,
}
sendWebhook(wh)
}
示例11: main
func main() {
v := new(Params)
r := new(plugin.Repo)
b := new(plugin.Build)
w := new(plugin.Workspace)
plugin.Param("repo", r)
plugin.Param("build", b)
plugin.Param("workspace", w)
plugin.Param("vargs", &v)
plugin.MustParse()
err := clone(r, b, w, v)
if err != nil {
os.Exit(1)
}
}
示例12: main
func main() {
fmt.Printf("Drone Mercurial Plugin built at %s\n", buildDate)
v := new(Params)
r := new(plugin.Repo)
b := new(plugin.Build)
w := new(plugin.Workspace)
plugin.Param("repo", r)
plugin.Param("build", b)
plugin.Param("workspace", w)
plugin.Param("vargs", &v)
plugin.MustParse()
err := run(r, b, w, v)
if err != nil {
os.Exit(1)
}
}
示例13: main
func main() {
fmt.Printf("Drone DockerHub Plugin built at %s\n", buildDate)
vargs := DockerHub{}
build := plugin.Build{}
plugin.Param("vargs", &vargs)
plugin.Param("build", &build)
if err := plugin.Parse(); err != nil {
println(err.Error())
os.Exit(1)
}
endpoint := fmt.Sprintf("https://registry.hub.docker.com/u/%s/trigger/%s/", vargs.Repo, vargs.Token)
values := DockerHubValues{SourceType: "Branch", SourceName: build.Branch}
values_json, err := json.Marshal(values)
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(values_json))
if err != nil {
fmt.Println(re.ReplaceAllString(err.Error(), "${1}HIDDEN"))
os.Exit(1)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
var resp *http.Response
err = try.Do(func(attempt int) (bool, error) {
var err error
resp, err = client.Do(req)
return attempt < 5, err
})
if err != nil {
fmt.Println(re.ReplaceAllString(err.Error(), "${1}HIDDEN"))
os.Exit(1)
}
resp.Body.Close()
}
示例14: main
func main() {
log.SetFlags(0)
plugin.Param("workspace", &workspace)
plugin.Param("vargs", &vargs)
plugin.MustParse()
sort.Strings(vargs.Gzip) // need for matchGzip
auth, err := google.JWTConfigFromJSON([]byte(vargs.AuthKey), storage.ScopeFullControl)
if err != nil {
fatalf("auth: %v", err)
}
ctx := context.Background()
client, err := storage.NewClient(ctx, cloud.WithTokenSource(auth.TokenSource(ctx)))
if err != nil {
fatalf("storage client: %v", err)
}
run(client)
os.Exit(ecode)
}
示例15: main
func main() {
repo := plugin.Repo{}
build := plugin.Build{}
system := plugin.System{}
vargs := Slack{}
plugin.Param("build", &build)
plugin.Param("repo", &repo)
plugin.Param("system", &system)
plugin.Param("vargs", &vargs)
// parse the parameters
if err := plugin.Parse(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
client.SetUrl(vargs.Webhook)
// generate the Slack message
msg := Message{}
msg.Username = vargs.Username
msg.Channel = vargs.Recipient
if len(vargs.Recipient) != 0 {
msg.Channel = Prepend("@", vargs.Recipient)
} else {
msg.Channel = Prepend("#", vargs.Channel)
}
attach := msg.NewAttachment()
attach.Text = GetMessage(repo, build, system, vargs)
attach.Fallback = GetFallback(&repo, &build)
attach.Color = GetColor(&build)
attach.MrkdwnIn = []string{"text", "fallback"}
// sends the message
if err := client.SendMessage(&msg); err != nil {
fmt.Println(err)
os.Exit(1)
}
}