plugin_release.go 2.1 KB
Newer Older
1 2 3
package cmd

import (
4
	"github.com/jenkins-zh/jenkins-cli/app/cmd/common"
5 6
	"os"

7 8
	"github.com/jenkins-zh/jenkins-cli/util"

9 10 11 12 13 14 15
	"github.com/jenkins-zh/jenkins-cli/app/i18n"

	"github.com/spf13/cobra"
)

// PluginReleaseOptions for the plugin create command
type PluginReleaseOptions struct {
16
	common.CommonOption
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

	Batch       bool
	Prepare     bool
	Perform     bool
	SkipTests   bool
	DebugOutput bool
}

var pluginReleaseOptions PluginReleaseOptions

func init() {
	pluginCmd.AddCommand(pluginReleaseCmd)
	pluginReleaseCmd.Flags().BoolVar(&pluginReleaseOptions.DebugOutput, "debug-output", false,
		i18n.T("If you want the maven output the debug info"))
	pluginReleaseCmd.Flags().BoolVar(&pluginReleaseOptions.Prepare, "prepare", true,
		i18n.T("Add mvn command release:prepare"))
	pluginReleaseCmd.Flags().BoolVar(&pluginReleaseOptions.Perform, "perform", true,
		i18n.T("Add mvn command release:perform"))
	pluginReleaseCmd.Flags().BoolVar(&pluginReleaseOptions.SkipTests, "skip-tests", true,
		i18n.T("Skip running tests"))
	pluginReleaseCmd.Flags().BoolVar(&pluginReleaseOptions.Batch, "batch", true,
		i18n.T("Run in non-interactive (batch)"))
}

var pluginReleaseCmd = &cobra.Command{
	Use:   "release",
	Short: i18n.T("Release current plugin project"),
	Long:  i18n.T("Release current plugin project"),
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		binary, err := util.LookPath("mvn", pluginReleaseOptions.LookPathContext)
		if err == nil {
			env := os.Environ()

			mvnArgs := []string{"mvn"}

			if pluginReleaseOptions.SkipTests {
				mvnArgs = append(mvnArgs, `-Darguments="-DskipTests"`)
			}

			if pluginReleaseOptions.Prepare {
				mvnArgs = append(mvnArgs, "release:prepare")
			}

			if pluginReleaseOptions.Perform {
				mvnArgs = append(mvnArgs, "release:perform")
			}

			if pluginReleaseOptions.Batch {
				mvnArgs = append(mvnArgs, "-B")
			}

			if pluginReleaseOptions.DebugOutput {
				mvnArgs = append(mvnArgs, "-X")
			}
			err = util.Exec(binary, mvnArgs, env, pluginReleaseOptions.SystemCallExec)
		}
		return
	},
75
	Annotations: map[string]string{
LinuxSuRen's avatar
LinuxSuRen 已提交
76
		common.Since: common.VersionSince0024,
77
	},
78
}