• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang plugin.Param函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/drone/drone-plugin-go/plugin.Param函数的典型用法代码示例。如果您正苦于以下问题:Golang Param函数的具体用法?Golang Param怎么用?Golang Param使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Param函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
		}
	}
}
开发者ID:donny-dont,项目名称:drone-git,代码行数:60,代码来源:main.go


示例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)
}
开发者ID:peterwang1996,项目名称:WebFundamentals,代码行数:34,代码来源:main.go


示例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
}
开发者ID:erickgnavar,项目名称:drone-rsync,代码行数:31,代码来源:main.go


示例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()
	}
}
开发者ID:MustWin,项目名称:drone-plugin-webhook,代码行数:25,代码来源:main.go


示例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.")
}
开发者ID:arobson,项目名称:drone-cowpoke,代码行数:35,代码来源:main.go


示例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)
	}
}
开发者ID:geoplex,项目名称:drone-plugin-bash,代码行数:26,代码来源:main.go


示例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()
	}
}
开发者ID:objectpartners,项目名称:drone-plugin-go,代码行数:33,代码来源:main.go


示例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")
	}

}
开发者ID:drone-plugins,项目名称:drone-terraform,代码行数:58,代码来源:main.go


示例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)
	}
}
开发者ID:RomanSaveljev,项目名称:drone-s3,代码行数:52,代码来源:main.go


示例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)
}
开发者ID:ipedrazas,项目名称:drone-kubernetes,代码行数:50,代码来源:main.go


示例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)
	}
}
开发者ID:msteinert,项目名称:drone-git,代码行数:16,代码来源:main.go


示例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)
	}
}
开发者ID:cedk,项目名称:drone-hg,代码行数:18,代码来源:main.go


示例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()
}
开发者ID:saward,项目名称:drone-dockerhub,代码行数:44,代码来源:main.go


示例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)
}
开发者ID:gtaylor,项目名称:drone-google-cloudstorage,代码行数:19,代码来源:main.go


示例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)
	}
}
开发者ID:cheif,项目名称:drone-slack,代码行数:42,代码来源:main.go


示例16: main

func main() {
	testExpressions()
	workspace := plugin.Workspace{}
	repo := plugin.Repo{}
	build := plugin.Build{}
	vargs := mavendeploy.Maven{}

	plugin.Param("repo", &repo)
	plugin.Param("build", &build)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	vargs.WorkspacePath(workspace.Path)

	err := vargs.Publish()
	if err != nil {
		panic(err)
	}
}
开发者ID:thomasf,项目名称:drone-mvn,代码行数:20,代码来源:main.go


示例17: main

func main() {
	fmt.Printf("Drone Google Cloud Storage Plugin built from %s\n", buildCommit)

	log.SetFlags(0)
	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()
	sort.Strings(vargs.Gzip) // need for matchGzip
	rand.Seed(time.Now().UnixNano())

	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)
}
开发者ID:drone-plugins,项目名称:drone-google-cloudstorage,代码行数:22,代码来源:main.go


示例18: main

func main() {
	workspace := plugin.Workspace{}
	build := plugin.Build{}
	vargs := Ansible{}

	plugin.Param("workspace", &workspace)
	plugin.Param("build", &build)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	vargs = setDefaults(vargs)

	// write the rsa private key
	if err := writeKey(workspace); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// write ansible configuration
	if err := writeAnsibleConf(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Run ansible
	cmd := command(vargs, workspace)
	trace(cmd)

	cmd.Env = os.Environ()
	cmd.Dir = workspace.Path
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	err := cmd.Run()
	if err != nil {
		fmt.Printf("Failed to deploy playbook %s with inventory %s: %s", vargs.Playbook, vargs.Inventory, err)
		os.Exit(1)
	}
}
开发者ID:rics3n,项目名称:drone-ansible,代码行数:39,代码来源:main.go


示例19: main

func main() {
	d := new(deployer)
	w := new(plugin.Workspace)

	plugin.Param("vargs", d)
	plugin.Param("workspace", w)
	plugin.MustParse()

	// Save ssh keys
	if err := os.MkdirAll("/root/.ssh", 0700); err != nil {
		log.Fatal(err)
	}

	if err := ioutil.WriteFile("/root/.ssh/config", []byte(SSHConfig), 0644); err != nil {
		log.Fatal(err)
	}

	if err := ioutil.WriteFile("/root/.ssh/id_rsa", []byte(w.Keys.Private), 0600); err != nil {
		log.Fatal(err)
	}

	if err := ioutil.WriteFile("/root/.ssh/id_rsa.pub", []byte(w.Keys.Public), 0644); err != nil {
		log.Fatal(err)
	}

	c := exec.Command("/bin/dep", "-n", d.Task, d.Stage)
	c.Dir = w.Path
	c.Stdout = os.Stdout
	c.Stderr = os.Stderr

	err := c.Run()
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Command completed successfully")
}
开发者ID:dizk,项目名称:drone-deployer,代码行数:37,代码来源:main.go


示例20: main

func main() {
	workspace := plugin.Workspace{}
	vargs := Fabric{}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)

	// parse the parameters
	if err := plugin.Parse(); err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	if err := writeKey(&workspace); err != nil {
		log.Println("Unable to write private key")
		log.Println(err)
		os.Exit(1)
	}

	if err := os.Chdir(workspace.Path); err != nil {
		log.Println("Unable to dc into workspace.Path")
		os.Exit(1)
	}

	for _, c := range vargs.Commands {
		fabArgs := strings.Split(c, " ")
		c := exec.Command("fab", fabArgs...)
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		err := c.Run()
		if err != nil {
			log.Println(err)
			os.Exit(101)
		}
	}
}
开发者ID:projectweekend,项目名称:drone-fabric,代码行数:36,代码来源:main.go



注:本文中的github.com/drone/drone-plugin-go/plugin.Param函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang parse.ContainerNode类代码示例发布时间:2022-05-23
下一篇:
Golang plugin.MustParse函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap