Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to clean the JENKINS_HOME before start run plugin #506

Merged
merged 1 commit into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ PATH := $(PATH):$(PWD)/bin
build: pre-build
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=$(BUILD_GOOS) GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/$(BUILD_GOOS)/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/$(BUILD_GOOS)/$(NAME)
rm -rf jcli && ln -s bin/$(BUILD_GOOS)/$(NAME) jcli
rm -rf $(NAME) && ln -s bin/$(BUILD_GOOS)/$(NAME) $(NAME)

darwin: pre-build
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/darwin/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/darwin/$(NAME)
rm -rf jcli && ln -s bin/darwin/$(NAME) jcli
rm -rf $(NAME) && ln -s bin/darwin/$(NAME) $(NAME)

linux: pre-build
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/linux/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/linux/$(NAME)
rm -rf jcli && ln -s bin/linux/$(NAME) jcli
rm -rf $(NAME) && ln -s bin/linux/$(NAME) $(NAME)

win: pre-build
go get github.com/inconshreveable/mousetrap
Expand All @@ -44,9 +44,9 @@ gen-mock:

release: build-all
mkdir -p release
cd ./bin/darwin; upx jcli; tar -zcvf ../../release/jcli-darwin-amd64.tar.gz jcli; cd ../../release/; shasum -a 256 jcli-darwin-amd64.tar.gz > jcli-darwin-amd64.txt
cd ./bin/linux; upx jcli; tar -zcvf ../../release/jcli-linux-amd64.tar.gz jcli; cd ../../release/; shasum -a 256 jcli-linux-amd64.tar.gz > jcli-linux-amd64.txt
cd ./bin/windows; upx jcli.exe; tar -zcvf ../../release/jcli-windows-386.tar.gz jcli.exe; cd ../../release/; shasum -a 256 jcli-windows-386.tar.gz > jcli-windows-386.txt
cd ./bin/darwin; upx $(NAME); tar -zcvf ../../release/$(NAME)-darwin-amd64.tar.gz $(NAME); cd ../../release/; shasum -a 256 $(NAME)-darwin-amd64.tar.gz > $(NAME)-darwin-amd64.txt
cd ./bin/linux; upx $(NAME); tar -zcvf ../../release/$(NAME)-linux-amd64.tar.gz $(NAME); cd ../../release/; shasum -a 256 $(NAME)-linux-amd64.tar.gz > $(NAME)-linux-amd64.txt
cd ./bin/windows; upx $(NAME).exe; tar -zcvf ../../release/$(NAME)-windows-386.tar.gz $(NAME).exe; cd ../../release/; shasum -a 256 $(NAME)-windows-386.tar.gz > $(NAME)-windows-386.txt

clean: ## Clean the generated artifacts
rm -rf bin release
Expand All @@ -56,10 +56,10 @@ clean: ## Clean the generated artifacts
rm -rf util/test-utils.xml

copy: darwin
sudo cp bin/darwin/$(NAME) /usr/local/bin/jcli
sudo cp bin/darwin/$(NAME) /usr/local/bin/$(NAME)

copy-linux: linux
sudo cp bin/linux/$(NAME) /usr/local/bin/jcli
sudo cp bin/linux/$(NAME) /usr/local/bin/$(NAME)

get-golint:
go get -u golang.org/x/lint/golint
Expand Down Expand Up @@ -161,7 +161,7 @@ gen-data:
cd app/i18n && go-bindata -o bindata.go -pkg i18n jcli/zh_CN/LC_MESSAGES/

image:
docker build . -t jenkinszh/jcli
docker build . -t jenkinszh/$(NAME)

setup-env-centos:
yum install make golang -y
19 changes: 17 additions & 2 deletions app/cmd/plugin_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,46 @@ import (
type PluginRunOptions struct {
common.Option

CleanHome bool
DebugOutput bool
}

var pluginRunOptions PluginRunOptions

func init() {
pluginCmd.AddCommand(pluginRunCmd)
pluginRunCmd.Flags().BoolVar(&pluginRunOptions.DebugOutput, "debug-output", false,

flags := pluginRunCmd.Flags()
flags.BoolVar(&pluginRunOptions.DebugOutput, "debug-output", false,
i18n.T("If you want the maven output the debug info"))
flags.BoolVarP(&pluginRunOptions.CleanHome, "clean-home", "", false,
i18n.T("If you want to clean the JENKINS_HOME before start it"))
}

var pluginRunCmd = &cobra.Command{
Use: "run",
Short: i18n.T("Run the Jenkins plugin project"),
Long: i18n.T(`Run the Jenkins plugin project
The default behaviour is "mvn hpi:run"`),
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
if pluginRunOptions.CleanHome {
err = os.RemoveAll("work")
}
return
},
RunE: func(cmd *cobra.Command, _ []string) (err error) {
binary, err := util.LookPath("mvn", pluginRunOptions.LookPathContext)
if err == nil {
env := os.Environ()

mvnArgs := []string{"mvn", "hpi:run", "-Dhpi.prefix=/", "-Djetty.port=8080"}
mvnArgs := []string{"mvn"}
if pluginRunOptions.DebugOutput {
mvnArgs = append(mvnArgs, "-X")
}
if pluginRunOptions.CleanHome {
mvnArgs = append(mvnArgs, "clean")
}
mvnArgs = append(mvnArgs, []string{"hpi:run", "-Dhpi.prefix=/", "-Djetty.port=8080"}...)
err = util.Exec(binary, mvnArgs, env, pluginRunOptions.SystemCallExec)
}
return
Expand Down