Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Jenkins 中文社区
jenkins-cli
提交
9b459862
J
jenkins-cli
项目概览
Jenkins 中文社区
/
jenkins-cli
通知
49
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins-cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
9b459862
编写于
7月 11, 2020
作者:
JenkinsInChina
提交者:
GitHub
7月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support to build job after saved it (#429)
上级
e7811b7d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
66 addition
and
6 deletion
+66
-6
app/cmd/job_edit.go
app/cmd/job_edit.go
+64
-6
docs/book/zh/job.md
docs/book/zh/job.md
+2
-0
未找到文件。
app/cmd/job_edit.go
浏览文件 @
9b459862
/*
MIT License
Copyright (c) 2019 Zhao Xiaojie
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package
cmd
import
(
...
...
@@ -21,22 +45,29 @@ type JobEditOption struct {
URL
string
Sample
bool
TrimSpace
bool
// Build flag indicates if trigger the Jenkins job after the action of edit
Build
bool
}
var
jobEditOption
JobEditOption
func
init
()
{
jobCmd
.
AddCommand
(
jobEditCmd
)
jobEditCmd
.
Flags
()
.
StringVarP
(
&
jobEditOption
.
URL
,
"url"
,
""
,
""
,
flags
:=
jobEditCmd
.
Flags
()
flags
.
StringVarP
(
&
jobEditOption
.
URL
,
"url"
,
""
,
""
,
i18n
.
T
(
"URL of the Jenkinsfile to files to use to replace pipeline"
))
jobEditCmd
.
Flags
()
.
StringVarP
(
&
jobEditOption
.
Filename
,
"filename"
,
"f"
,
""
,
flags
.
StringVarP
(
&
jobEditOption
.
Filename
,
"filename"
,
"f"
,
""
,
i18n
.
T
(
"Filename to files to use to replace pipeline"
))
jobEditCmd
.
Flags
()
.
StringVarP
(
&
jobEditOption
.
Script
,
"script"
,
"s"
,
""
,
flags
.
StringVarP
(
&
jobEditOption
.
Script
,
"script"
,
"s"
,
""
,
i18n
.
T
(
"Script to use to replace pipeline. Use script first if you give filename at the meantime."
))
jobEditCmd
.
Flags
()
.
BoolVarP
(
&
jobEditOption
.
Sample
,
"sample"
,
""
,
false
,
flags
.
BoolVarP
(
&
jobEditOption
.
Sample
,
"sample"
,
""
,
false
,
i18n
.
T
(
"Give it a sample Jenkinsfile if the target script is empty"
))
jobEditCmd
.
Flags
()
.
BoolVarP
(
&
jobEditOption
.
TrimSpace
,
"trim"
,
""
,
true
,
flags
.
BoolVarP
(
&
jobEditOption
.
TrimSpace
,
"trim"
,
""
,
true
,
i18n
.
T
(
"If trim the leading and tailing white space"
))
flags
.
BoolVarP
(
&
jobEditOption
.
Build
,
"build"
,
"b"
,
false
,
i18n
.
T
(
"Indicates if trigger the Jenkins job after the action of edit"
))
jobEditOption
.
Stdio
=
common
.
GetSystemStdio
()
}
...
...
@@ -57,7 +88,7 @@ Official Pipeline syntax document is here https://jenkins.io/doc/book/pipeline/s
RoundTripper
:
jobEditOption
.
RoundTripper
,
},
}
getCurrentJenkinsAndClient
OrDie
(
&
(
jclient
.
JenkinsCore
))
getCurrentJenkinsAndClient
(
&
(
jclient
.
JenkinsCore
))
if
content
,
err
=
jobEditOption
.
getPipeline
(
jclient
,
name
);
err
==
nil
{
if
jobEditOption
.
TrimSpace
{
...
...
@@ -65,6 +96,11 @@ Official Pipeline syntax document is here https://jenkins.io/doc/book/pipeline/s
}
err
=
jclient
.
UpdatePipeline
(
name
,
content
)
}
// just trigger the Jenkins job when edit it successfully
if
err
==
nil
&&
jobEditOption
.
Build
{
err
=
jclient
.
Build
(
name
)
}
return
},
}
...
...
@@ -74,10 +110,32 @@ func (j *JobEditOption) getSampleJenkinsfile() string {
agent {
label 'master'
}
options {
timeout(time: 1, unit: 'HOURS')
}
environment {
NAME = 'jack'
}
stages {
stage('Example') {
steps {
echo 'Hello World'
echo env.NAME
}
}
stage('Parallel Stage') {
failFast true
parallel {
stage('Brother A') {
steps {
echo "On Brother A"
}
}
stage('Brother B') {
steps {
echo "On Brother B"
}
}
}
}
}
...
...
docs/book/zh/job.md
浏览文件 @
9b459862
...
...
@@ -49,6 +49,8 @@ pipeline {
如果希望能快速地给出一个流水线的样例的话,当在流水线脚本为空时,可以执行命令:
`jcli job edit test --sample`
如果希望编辑流水线并保存退出后,直接触发的话,可以使用对应的参数来实现:
`jcli job edit test --build`
## 禁用
禁用任务:
`jcli job disable job/test/`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录