Exemple #1
0
func main() {
	if len(os.Args) != 3 {
		usage(fmt.Errorf("Wrong number of arguments"))
	}

	f, err := file()
	failOnError(err)
	defer f.Close()

	pipeline, err := pipeline.NewJenkinsPipeline(f)
	failOnError(err)

	jenkins := pipeline.JenkinsServer
	name, err := pipeline.DefaultName()
	failOnError(err)

	switch os.Args[1] {
	case "delete":
		_, err := jenkins.DeletePipeline(name)
		failOnError(err)
	case "update":
		var url string
		url, err := pipeline.UpdatePipeline(name)
		failOnError(err)
		fmt.Println(url)
	case "create":
		url, err := pipeline.CreatePipeline(name)
		failOnError(err)
		fmt.Println(url)
	default:
		usage(fmt.Errorf("Unkown command %s", os.Args[0]))
	}
}
func main() {
	// uncomment for debug information
	// pipeline.DebugLogger = os.Stderr
	var err error
	flag.Parse()
	args := flag.Args()
	f, err := os.Open("Pipeline.example")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to open file Pipeline.example: %s", err.Error())
		os.Exit(1)
	}
	defer f.Close()

	pipeline, err := pipeline.NewJenkinsPipeline(f)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err.Error())
		os.Exit(1)
	}
	js := pipeline.JenkinsServer

	name, err := pipeline.DefaultName()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Please provide 'default-name' setting")
		os.Exit(2)
	}

	switch args[0] {
	case "delete":
		_, err = js.DeletePipeline(name)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error: %s", err)
		}
	case "update":
		var url string
		url, err = pipeline.UpdatePipeline(name)
		if err == nil {
			fmt.Printf("%s\n", url)
		} else {
			fmt.Fprintf(os.Stderr, "error: %s", err)
		}
	case "create":
		var url string
		url, err = pipeline.CreatePipeline(name)
		if err == nil {
			fmt.Printf("%s\n", url)
		} else {
			fmt.Fprintf(os.Stderr, "error: %s", err)
		}
	default:
		usage(fmt.Errorf("unknown 'dp' subCommand: '%s'", args))
	}
}