未验证 提交 7c3092fe 编写于 作者: LinuxSuRen's avatar LinuxSuRen 提交者: GitHub

Merge pull request #248 from LinuxSuRen/stop-last-build

Add support to stop the last build
package cmd
import (
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/spf13/cobra"
)
......@@ -18,8 +19,8 @@ func init() {
var jobCmd = &cobra.Command{
Use: "job",
Short: "Manage the job of your Jenkins",
Long: `Manage the job of your Jenkins
Short: i18n.T("Manage the job of your Jenkins"),
Long: i18n.T(`Manage the job of your Jenkins
Editing the pipeline job needs to install a plugin which is pipeline-restful-api
https://plugins.jenkins.io/pipeline-restful-api`,
https://plugins.jenkins.io/pipeline-restful-api`),
}
......@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"path/filepath"
"strconv"
......@@ -27,15 +28,18 @@ var jobArtifactDownloadOption JobArtifactDownloadOption
func init() {
jobArtifactCmd.AddCommand(jobArtifactDownloadCmd)
jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.ID, "id", "i", "", "ID of the job artifact")
jobArtifactDownloadCmd.Flags().BoolVarP(&jobArtifactDownloadOption.ShowProgress, "progress", "", true, "Whether show the progress")
jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.DownloadDir, "download-dir", "", "", "The directory which artifact will be downloaded")
jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.ID, "id", "i", "",
i18n.T("ID of the job artifact"))
jobArtifactDownloadCmd.Flags().BoolVarP(&jobArtifactDownloadOption.ShowProgress, "progress", "", true,
i18n.T("Whether show the progress"))
jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.DownloadDir, "download-dir", "", "",
i18n.T("The directory which artifact will be downloaded"))
}
var jobArtifactDownloadCmd = &cobra.Command{
Use: "download <jobName> [buildID]",
Short: "Download the artifact of target job",
Long: `Download the artifact of target job`,
Short: i18n.T("Download the artifact of target job"),
Long: i18n.T(`Download the artifact of target job`),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
argLen := len(args)
......
......@@ -3,6 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"log"
"net/http"
......@@ -32,8 +33,8 @@ func init() {
var jobBuildCmd = &cobra.Command{
Use: "build <jobName>",
Short: "Build the job of your Jenkins",
Long: `Build the job of your Jenkins`,
Short: i18n.T("Build the job of your Jenkins"),
Long: i18n.T("Build the job of your Jenkins"),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
name := args[0]
......
package cmd
import (
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"github.com/AlecAivazis/survey/v2"
"github.com/jenkins-zh/jenkins-cli/app/helper"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
......@@ -28,10 +28,10 @@ func init() {
var jobCreateCmd = &cobra.Command{
Use: "create <jobName>",
Short: "Create a job in your Jenkins",
Long: `Create a job in your Jenkins`,
Short: i18n.T("Create a job in your Jenkins"),
Long: i18n.T(`Create a job in your Jenkins`),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) (err error) {
jobName := args[0]
jclient := &client.JobClient{
JenkinsCore: client.JenkinsCore{
......@@ -41,7 +41,6 @@ var jobCreateCmd = &cobra.Command{
getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
var createMode string
var err error
if createMode, err = jobCreateOption.getCreateMode(jclient); err == nil {
payload := client.CreateJobPayload{
Name: jobName,
......@@ -54,7 +53,7 @@ var jobCreateCmd = &cobra.Command{
}
err = jclient.Create(payload)
}
helper.CheckErr(cmd, err)
return
},
}
......
......@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"github.com/jenkins-zh/jenkins-cli/app/helper"
......@@ -26,8 +27,8 @@ func init() {
var jobDeleteCmd = &cobra.Command{
Use: "delete <jobName>",
Short: "Delete a job in your Jenkins",
Long: `Delete a job in your Jenkins`,
Short: i18n.T("Delete a job in your Jenkins"),
Long: i18n.T("Delete a job in your Jenkins"),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
jobName := args[0]
......
package cmd
import (
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"io/ioutil"
"net/http"
"github.com/AlecAivazis/survey/v2"
"github.com/jenkins-zh/jenkins-cli/app/helper"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
)
......@@ -25,22 +24,21 @@ var jobEditOption JobEditOption
func init() {
jobCmd.AddCommand(jobEditCmd)
jobEditCmd.Flags().StringVarP(&jobEditOption.URL, "url", "", "",
"URL of the Jenkinsfile to files to use to replace pipeline")
i18n.T("URL of the Jenkinsfile to files to use to replace pipeline"))
jobEditCmd.Flags().StringVarP(&jobEditOption.Filename, "filename", "f", "",
"Filename to files to use to replace pipeline")
i18n.T("Filename to files to use to replace pipeline"))
jobEditCmd.Flags().StringVarP(&jobEditOption.Script, "script", "s", "",
"Script to use to replace pipeline. Use script first if you give filename at the meantime.")
i18n.T("Script to use to replace pipeline. Use script first if you give filename at the meantime."))
}
var jobEditCmd = &cobra.Command{
Use: "edit <jobName>",
Short: "Edit the job of your Jenkins",
Long: `Edit the job of your Jenkins. We only support to edit the pipeline job.`,
Short: i18n.T("Edit the job of your Jenkins"),
Long: i18n.T(`Edit the job of your Jenkins. We only support to edit the pipeline job.`),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) (err error) {
name := args[0]
var content string
var err error
jclient := &client.JobClient{
JenkinsCore: client.JenkinsCore{
......@@ -52,7 +50,7 @@ var jobEditCmd = &cobra.Command{
if content, err = jobEditOption.getPipeline(jclient, name); err == nil {
err = jclient.UpdatePipeline(name, content)
}
helper.CheckErr(cmd, err)
return
},
}
......
......@@ -3,7 +3,7 @@ package cmd
import (
"bytes"
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/helper"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/jenkins-zh/jenkins-cli/util"
"github.com/spf13/cobra"
......@@ -26,10 +26,10 @@ func init() {
var jobHistoryCmd = &cobra.Command{
Use: "history <jobName>",
Short: "Print the history of job in your Jenkins",
Long: `Print the history of job in your Jenkins`,
Short: i18n.T("Print the history of job in your Jenkins"),
Long: i18n.T(`Print the history of job in your Jenkins`),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) (err error) {
jobName := args[0]
jClient := &client.JobClient{
......@@ -39,7 +39,8 @@ var jobHistoryCmd = &cobra.Command{
}
getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
builds, err := jClient.GetHistory(jobName)
var builds []*client.JobBuild
builds, err = jClient.GetHistory(jobName)
if err == nil {
var data []byte
data, err = jobHistoryOption.Output(builds)
......@@ -47,7 +48,7 @@ var jobHistoryCmd = &cobra.Command{
cmd.Print(string(data))
}
}
helper.CheckErr(cmd, err)
return
},
}
......
......@@ -3,6 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"log"
"net/http"
"strconv"
......@@ -27,19 +28,16 @@ var jobInputOption JobInputOption
func init() {
jobCmd.AddCommand(jobInputCmd)
jobInputCmd.Flags().StringVarP(&jobInputOption.Action, "action", "", "", "The action wether you want to process or abort.")
jobInputCmd.Flags().StringVarP(&jobInputOption.Action, "action", "", "",
i18n.T("The action whether you want to process or abort."))
}
var jobInputCmd = &cobra.Command{
Use: "input <jobName> [buildID]",
Short: "Input a job in your Jenkins",
Long: `Input a job in your Jenkins`,
Short: i18n.T("Input a job in your Jenkins"),
Long: i18n.T("Input a job in your Jenkins"),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
cmd.Help()
return
}
jobName := args[0]
buildID := -1
......
......@@ -7,7 +7,6 @@ import (
"github.com/jenkins-zh/jenkins-cli/client"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/cobra"
"io/ioutil"
"os"
......@@ -54,16 +53,12 @@ var _ = Describe("job input command", func() {
rootCmd.SetArgs([]string{"job", "input"})
jobInputCmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) {
cmd.Print("help")
})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(err).To(HaveOccurred())
Expect(buf.String()).To(Equal("help"))
Expect(buf.String()).To(ContainSubstring("Error: requires at least 1 arg(s)"))
})
It("should success, abort without inputs", func() {
......
package cmd
import (
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"time"
......@@ -24,16 +25,19 @@ var jobLogOption JobLogOption
func init() {
jobCmd.AddCommand(jobLogCmd)
jobLogCmd.Flags().IntVarP(&jobLogOption.History, "history", "s", -1, "Specific build history of log")
jobLogCmd.Flags().BoolVarP(&jobLogOption.Watch, "watch", "w", false, "Watch the job logs")
jobLogCmd.Flags().IntVarP(&jobLogOption.Interval, "interval", "i", 1, "Interval of watch")
jobLogCmd.Flags().IntVarP(&jobLogOption.History, "history", "s", -1,
i18n.T("Specific build history of log"))
jobLogCmd.Flags().BoolVarP(&jobLogOption.Watch, "watch", "w", false,
i18n.T("Watch the job logs"))
jobLogCmd.Flags().IntVarP(&jobLogOption.Interval, "interval", "i", 1,
i18n.T("Interval of watch"))
}
var jobLogCmd = &cobra.Command{
Use: "log <jobName> [buildID]",
Short: "Print the job's log of your Jenkins",
Long: `Print the job's log of your Jenkins
It'll print the log text of the last build if you don't give the build id.`,
Short: i18n.T("Print the job's log of your Jenkins"),
Long: i18n.T(`Print the job's log of your Jenkins
It'll print the log text of the last build if you don't give the build id.`),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
name := args[0]
......
......@@ -2,6 +2,7 @@ package cmd
import (
"encoding/json"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"github.com/jenkins-zh/jenkins-cli/app/helper"
......@@ -29,8 +30,8 @@ func init() {
var jobParamCmd = &cobra.Command{
Use: "param <jobName>",
Short: "Get parameters of the job of your Jenkins",
Long: `Get parameters of the job of your Jenkins`,
Short: i18n.T("Get parameters of the job of your Jenkins"),
Long: i18n.T("Get parameters of the job of your Jenkins"),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
name := args[0]
......
......@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"strings"
......@@ -24,16 +25,18 @@ var jobSearchOption JobSearchOption
func init() {
jobCmd.AddCommand(jobSearchCmd)
jobSearchCmd.Flags().IntVarP(&jobSearchOption.Max, "max", "", 10, "The number of limitation to print")
jobSearchCmd.Flags().BoolVarP(&jobSearchOption.PrintAll, "all", "", false, "Print all items if there's no keyword")
jobSearchCmd.Flags().IntVarP(&jobSearchOption.Max, "max", "", 10,
i18n.T("The number of limitation to print"))
jobSearchCmd.Flags().BoolVarP(&jobSearchOption.PrintAll, "all", "", false,
i18n.T("Print all items if there's no keyword"))
jobSearchCmd.Flags().StringVarP(&jobSearchOption.Format, "output", "o", "json",
`Formats of the output which contain name, path`)
i18n.T(`Formats of the output which contain name, path`))
}
var jobSearchCmd = &cobra.Command{
Use: "search [keyword]",
Short: "Print the job of your Jenkins",
Long: `Print the job of your Jenkins`,
Short: i18n.T("Print the job of your Jenkins"),
Long: i18n.T(`Print the job of your Jenkins`),
Run: func(cmd *cobra.Command, args []string) {
if !jobSearchOption.PrintAll && len(args) == 0 {
cmd.Help()
......
......@@ -2,13 +2,11 @@ package cmd
import (
"fmt"
"net/http"
"strconv"
"github.com/jenkins-zh/jenkins-cli/app/helper"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
"net/http"
"strconv"
)
// JobStopOption is the job stop option
......@@ -26,18 +24,16 @@ func init() {
}
var jobStopCmd = &cobra.Command{
Use: "stop <jobName> <buildNumber>",
Short: "Stop a job build in your Jenkins",
Long: `Stop a job build in your Jenkins`,
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
var (
buildNum int
err error
)
if buildNum, err = strconv.Atoi(args[1]); err != nil {
cmd.PrintErrln(err)
return
Use: "stop <jobName> [buildNumber]",
Short: i18n.T("Stop a job build in your Jenkins"),
Long: i18n.T("Stop a job build in your Jenkins"),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
buildNum := -1
if len(args) > 1 {
if buildNum, err = strconv.Atoi(args[1]); err != nil {
return
}
}
jobName := args[0]
......@@ -52,7 +48,6 @@ var jobStopCmd = &cobra.Command{
}
getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
err = jclient.StopJob(jobName, buildNum)
helper.CheckErr(cmd, err)
return jclient.StopJob(jobName, buildNum)
},
}
......@@ -70,7 +70,7 @@ var _ = Describe("job stop command", func() {
roundTripper.EXPECT().
RoundTrip(requestCrumb).Return(responseCrumb, nil)
rootCmd.SetArgs([]string{"job", "stop", jobName, "1", "-b", "true"})
rootCmd.SetArgs([]string{"job", "stop", jobName, "1", "-b"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
......@@ -79,5 +79,59 @@ var _ = Describe("job stop command", func() {
Expect(buf.String()).To(Equal(""))
})
It("stop the last build, with batch mode", func() {
data, err := generateSampleConfig()
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
jobName := "fakeJob"
request, _ := http.NewRequest("POST", fmt.Sprintf("http://localhost:8080/jenkins/job/%s/lastBuild/stop", jobName), nil)
request.Header.Add("CrumbRequestField", "Crumb")
request.SetBasicAuth("admin", "111e3a2f0231198855dceaff96f20540a9")
response := &http.Response{
StatusCode: 200,
Proto: "HTTP/1.1",
Request: request,
Body: ioutil.NopCloser(bytes.NewBufferString("")),
}
roundTripper.EXPECT().
RoundTrip(request).Return(response, nil)
requestCrumb, _ := http.NewRequest("GET", "http://localhost:8080/jenkins/crumbIssuer/api/json", nil)
requestCrumb.SetBasicAuth("admin", "111e3a2f0231198855dceaff96f20540a9")
responseCrumb := &http.Response{
StatusCode: 200,
Proto: "HTTP/1.1",
Request: requestCrumb,
Body: ioutil.NopCloser(bytes.NewBufferString(`
{"crumbRequestField":"CrumbRequestField","crumb":"Crumb"}
`)),
}
roundTripper.EXPECT().
RoundTrip(requestCrumb).Return(responseCrumb, nil)
rootCmd.SetArgs([]string{"job", "stop", jobName, "-b"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err = rootCmd.ExecuteC()
Expect(err).To(BeNil())
Expect(buf.String()).To(Equal(""))
})
It("stop the last build, with batch mode", func() {
jobName := "fakeJob"
rootCmd.SetArgs([]string{"job", "stop", jobName, "not-number", "-b"})
buf := new(bytes.Buffer)
rootCmd.SetOutput(buf)
_, err := rootCmd.ExecuteC()
Expect(err).To(HaveOccurred())
Expect(buf.String()).To(ContainSubstring("Error: strconv.Atoi: parsing"))
})
})
})
......@@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"net/http"
"github.com/jenkins-zh/jenkins-cli/app/helper"
......@@ -28,8 +29,8 @@ func init() {
var jobTypeCmd = &cobra.Command{
Use: "type",
Short: "Print the types of job which in your Jenkins",
Long: `Print the types of job which in your Jenkins`,
Short: i18n.T("Print the types of job which in your Jenkins"),
Long: i18n.T("Print the types of job which in your Jenkins"),
Run: func(cmd *cobra.Command, _ []string) {
jclient := &client.JobClient{
JenkinsCore: client.JenkinsCore{
......
......@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"log"
"os/exec"
"runtime"
......@@ -22,15 +23,17 @@ var openOption OpenOption
func init() {
rootCmd.AddCommand(openCmd)
openCmd.Flags().StringVarP(&openOption.Name, "name", "n", "", "Open a specific Jenkins by name")
openCmd.Flags().BoolVarP(&openOption.Config, "config", "c", false, "Open the configuration page of Jenkins")
openCmd.Flags().StringVarP(&openOption.Name, "name", "n", "",
i18n.T("Open a specific Jenkins by name"))
openCmd.Flags().BoolVarP(&openOption.Config, "config", "c", false,
i18n.T("Open the configuration page of Jenkins"))
openOption.SetFlag(openCmd)
}
var openCmd = &cobra.Command{
Use: "open [config name]",
Short: "Open your Jenkins with a browse",
Long: `Open your Jenkins with a browse`,
Short: i18n.T("Open your Jenkins with a browse"),
Long: i18n.T(`Open your Jenkins with a browse`),
Example: `jcli open -n <config name>`,
Run: func(_ *cobra.Command, args []string) {
var jenkins *JenkinsServer
......
......@@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/helper"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"io/ioutil"
"net/http"
......@@ -23,8 +24,8 @@ func init() {
var pluginCheckCmd = &cobra.Command{
Use: "check",
Short: "Check update center server",
Long: `Check update center server`,
Short: i18n.T("Check update center server"),
Long: i18n.T(`Check update center server`),
Run: func(cmd *cobra.Command, _ []string) {
jClient := &client.PluginManager{
JenkinsCore: client.JenkinsCore{
......
......@@ -33,8 +33,8 @@ func init() {
var pluginInstallCmd = &cobra.Command{
Use: "install [pluginName]",
Short: i18n.T("Install the plugins"),
Long: `Install the plugins
Allow you to install a plugin with or without the version`,
Long: i18n.T(`Install the plugins
Allow you to install a plugin with or without the version`),
Example: `jcli plugin install localization-zh-cn
jcli plugin install localization-zh-cn@1.0.9
`,
......
......@@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: EMAIL\n"
"POT-Creation-Date: 2019-11-21 13:00+0800\n"
"PO-Revision-Date: 2019-11-21 22:17+0800\n"
"PO-Revision-Date: 2019-11-22 23:01+0800\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
......@@ -18,17 +18,45 @@ msgstr ""
"Plural-Forms: nplurals=1; plural=0;\n"
"Language: zh_CN\n"
#: app/cmd/job_type.go:32 app/cmd/job_type.go:33
msgid "Print the types of job which in your Jenkins"
msgstr ""
#: app/cmd/plugin_check.go:27 app/cmd/plugin_check.go:28
msgid "Check update center server"
msgstr ""
#: app/cmd/center_download.go:44
msgid "Download Jenkins from a mirror site. You can get more mirror sites from https://jenkins-zh.cn/tutorial/management/mirror/"
msgstr ""
#: app/cmd/job.go:22
msgid "Manage the job of your Jenkins"
msgstr ""
#: app/cmd/job_artifact_download.go:34
msgid "Whether show the progress"
msgstr "是否显示进度条"
#: app/cmd/job_edit.go:29
msgid "Filename to files to use to replace pipeline"
msgstr ""
#: app/cmd/plugin_download.go:36
msgid "Download the plugins"
msgstr "下载插件"
#: app/cmd/restart.go:29 app/cmd/restart.go:30
msgid "Restart your Jenkins"
msgstr ""
msgid "Restart your Jenkins"
msgstr "重启 Jenkins"
#: app/cmd/root.go:79
msgid "Select a Jenkins server for this time"
msgstr "选择本次执行的 Jenkins"
#: app/cmd/config_add.go:30
msgid "Proxy of the Jenkins"
msgstr ""
msgid "Proxy of the Jenkins"
msgstr "Jenkins 的代理"
#: app/cmd/plugin_upgrade.go:32 app/cmd/plugin_upgrade.go:33
msgid "Upgrade the specific plugin"
......@@ -39,8 +67,8 @@ msgid "Manage the config of jcli"
msgstr "管理 jcli 的配置"
#: app/cmd/config_generate.go:28
msgid "Copy the output into clipboard"
msgstr "拷贝输出到剪贴板"
msgid "Copy the output into clipboard"
msgstr "拷贝输出到剪贴板"
#: app/cmd/root.go:77
msgid "An alternative config file"
......@@ -50,9 +78,25 @@ msgstr "指定另外一个配置文件"
msgid "List all Jenkins config items"
msgstr "列出所有的 Jenkins 配置项"
#: app/cmd/job_edit.go:31
msgid "Script to use to replace pipeline. Use script first if you give filename at the meantime."
msgstr ""
#: app/cmd/job_input.go:37 app/cmd/job_input.go:38
msgid "Input a job in your Jenkins"
msgstr ""
#: app/cmd/job_log.go:38
msgid "Print the job's log of your Jenkins"
msgstr "输出任务的日志"
#: app/cmd/config_generate.go:34 app/cmd/config_generate.go:35
msgid "Generate a sample config file for you"
msgstr "为你生成一份样本配置文件"
#: app/cmd/doc.go:30 app/cmd/doc.go:31
msgid "Generate document for all jcl commands"
msgstr "为所有的 jcli 命令生成文档"
msgid "Generate document for all jcl commands"
msgstr "为所有的 jcli 命令生成文档"
#: app/cmd/root.go:37
msgid "jcli is a tool which could help you with your multiple Jenkins"
......@@ -75,8 +119,8 @@ msgid "Print the version of Jenkins CLI"
msgstr "打印 Jenkins CLI 的版本"
#: app/cmd/completion.go:14 app/cmd/completion.go:15
msgid "Genereate bash completion scripts"
msgstr "生成 bash 自动补全的脚本"
msgid "Genereate bash completion scripts"
msgstr "生成 bash 自动补全的脚本"
#: app/cmd/plugin_download.go:31 app/cmd/plugin_install.go:29
msgid "If you want to show the progress of download a plugin"
......@@ -84,7 +128,7 @@ msgstr "你是否希望显示插件下载的进度"
#: app/cmd/plugin_download.go:37
msgid "Download the plugins which contain the target plugin and its dependencies"
msgstr ""
msgstr "下载插件及其依赖"
#: app/cmd/plugin_uninstall.go:26 app/cmd/plugin_uninstall.go:27
msgid "Uninstall the plugins"
......@@ -99,44 +143,32 @@ msgid "Whether skip the post command hook"
msgstr "是否跳过后置命令钩子"
#: app/cmd/center_download.go:32
msgid "Version of the Jenkins which you want to download"
msgstr ""
msgid "Version of the Jenkins which you want to download"
msgstr "你希望下载的 Jenkins 版本"
#: app/cmd/config_add.go:22
msgid "Name of the Jenkins"
msgstr ""
#: app/cmd/config_list.go:28 app/cmd/config_list.go:29
msgid "List all Jenkins config items"
msgstr ""
#: app/cmd/config_generate.go:34 app/cmd/config_generate.go:35
msgid "Generate a sample config file for you"
msgstr ""
msgid "Name of the Jenkins"
msgstr "Jenkins 的名称"
#: app/cmd/config_add.go:28
msgid "Token of the Jenkins"
msgstr ""
msgid "Token of the Jenkins"
msgstr "Jenkins 的令牌"
#: app/cmd/config_add.go:32
msgid "ProxyAuth of the Jenkins"
msgstr ""
#: app/cmd/root.go:36
msgid "jcli is a tool which could help you with your multiple Jenkins"
msgstr ""
msgid "ProxyAuth of the Jenkins"
msgstr ""
#: app/cmd/center_watch.go:27
msgid "The watch will be continue util Jenkins needs restart"
msgstr ""
msgid "The watch will be continue util Jenkins needs restart"
msgstr ""
#: app/cmd/config_add.go:26
msgid "UserName of the Jenkins"
msgstr ""
msgid "UserName of the Jenkins"
msgstr "Jenkins 的用户名"
#: app/cmd/config_edit.go:21 app/cmd/config_edit.go:22
msgid "Edit a Jenkins config"
msgstr ""
msgid "Edit a Jenkins config"
msgstr "编辑 Jenkins 配置"
#: app/cmd/plugin_download.go:25
msgid "If you want to skip download dependency of plugin"
......@@ -144,7 +176,7 @@ msgstr "你是否想要跳过下载依赖插件"
#: app/cmd/plugin_upload.go:45
msgid "Password of remote plugin URL"
msgstr ""
msgstr "远程插件的秘密"
#: app/cmd/plugin_upload.go:58
msgid "Upload a plugin to your Jenkins"
......@@ -156,15 +188,15 @@ msgstr "管理你的 Jenkins 更新中心"
#: app/cmd/job_artifact.go:33 app/cmd/job_artifact.go:34
msgid "Print the artifact list of target job"
msgstr ""
msgstr "输出目标任务的归档文件列表"
#: app/cmd/plugin_download.go:27
msgid "If you want to skip download optional dependency of plugin"
msgstr ""
#: app/cmd/job_search.go:29
msgid "The number of limitation to print"
msgstr "输出的数量限制"
#: app/cmd/plugin_download.go:36
msgid "Download the plugins"
msgstr "下载插件"
#: app/cmd/open.go:29
msgid "Open the configuration page of Jenkins"
msgstr ""
#: app/cmd/plugin_install.go:35
msgid "Install the plugins"
......@@ -188,52 +220,20 @@ msgstr "你是否想要从镜像站点下载插件"
#: app/cmd/plugin_list.go:35 app/cmd/plugin_list.go:36
msgid "Print all the plugins which are installed"
msgstr ""
msgstr "输出已经安装的插件"
#: app/cmd/center_watch.go:29
msgid "The watch will be continue util all Jenkins plugins installation is completed"
msgstr ""
msgid "The watch will be continue util all Jenkins plugins installation is completed"
msgstr ""
#: app/cmd/common.go:101 app/cmd/config_generate.go:26
msgid "Interactive mode"
msgstr ""
#: app/cmd/plugin_download.go:29 app/cmd/plugin_install.go:27
msgid "If you want to download plugin from a mirror site"
msgstr ""
msgid "Interactive mode"
msgstr "交互模式"
#: app/cmd/plugin_upload.go:43
msgid "User of remote plugin URL"
msgstr ""
#: app/cmd/plugin_upload.go:47
msgid "Remote Jenkins which will find from config list"
msgstr ""
#: app/cmd/plugin_upload.go:58
msgid "Upload a plugin to your Jenkins"
msgstr ""
#: app/cmd/root.go:76
msgid "An alternative config file"
msgstr ""
#: app/cmd/center.go:31 app/cmd/center.go:32
msgid "Manage your update center"
msgstr ""
#: app/cmd/center_download.go:36
msgid "If you want to show the download progress"
msgstr ""
#: app/cmd/completion.go:14 app/cmd/completion.go:15
msgid "Genereate bash completion scripts"
msgstr ""
#: app/cmd/config.go:32 app/cmd/config.go:33
msgid "Manage the config of jcli"
msgstr "管理 jcli 的配置信息"
#: app/cmd/plugin_upload.go:59
msgid "Upload a plugin from local filesystem or remote URL to your Jenkins"
msgstr "上传来自本地文件系统或者远程 URL 的插件到你的 Jenkins"
......@@ -69,7 +69,13 @@ func (q *JobClient) BuildWithParams(jobName string, parameters []ParameterDefini
// StopJob stops a job build
func (q *JobClient) StopJob(jobName string, num int) (err error) {
path := ParseJobPath(jobName)
api := fmt.Sprintf("%s/%d/stop", path, num)
var api string
if num <= 0 {
api = fmt.Sprintf("%s/lastBuild/stop", path)
} else {
api = fmt.Sprintf("%s/%d/stop", path, num)
}
_, err = q.RequestWithoutData("POST", api, nil, nil, 200)
return
......
......@@ -219,6 +219,36 @@ var _ = Describe("job test", func() {
err := jobClient.StopJob(jobName, buildID)
Expect(err).To(BeNil())
})
It("stop the last job build without a folder", func() {
jobName := "fakeJob"
buildID := -1
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/job/%s/lastBuild/stop", jobClient.URL, jobName), nil)
request.Header.Add("CrumbRequestField", "Crumb")
response := &http.Response{
StatusCode: 200,
Proto: "HTTP/1.1",
Request: request,
Body: ioutil.NopCloser(bytes.NewBufferString("")),
}
roundTripper.EXPECT().
RoundTrip(request).Return(response, nil)
requestCrumb, _ := http.NewRequest("GET", fmt.Sprintf("%s%s", jobClient.URL, "/crumbIssuer/api/json"), nil)
responseCrumb := &http.Response{
StatusCode: 200,
Proto: "HTTP/1.1",
Request: requestCrumb,
Body: ioutil.NopCloser(bytes.NewBufferString(`
{"crumbRequestField":"CrumbRequestField","crumb":"Crumb"}
`)),
}
roundTripper.EXPECT().
RoundTrip(requestCrumb).Return(responseCrumb, nil)
err := jobClient.StopJob(jobName, buildID)
Expect(err).To(BeNil())
})
})
Context("GetJob", func() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册