[pipeline]update

4.0
vapao 2023-06-25 18:17:23 +08:00
parent 0b5895bc41
commit aea4336b81
4 changed files with 73 additions and 17 deletions

View File

@ -95,12 +95,18 @@ class DoView(View):
item['_targets'] = [{'id': x, 'name': host_map[x]} for x in item['destination']['targets']]
if item['module'] == 'parameter':
dynamic_params = item.get('dynamic_params')
if item.get('dynamic_params'):
dynamic_params.extend(item['dynamic_params'])
elif item['module'] == 'build':
if item.get('git_commit') == 'selective':
dynamic_params.append({'variable': 'git_commit', 'name': 'Git提交', 'type': 'select', 'options': [{'value': 1, 'label': 1}], 'required': True})
elif item.get('git_tag') == 'selective':
dynamic_params.append({'variable': 'tag_', 'name': 'Git标签', 'type': 'text', 'required': True})
elif item['module'] == 'data_upload':
tmp = {'variable': item['id'], 'name': item['name'], 'type': 'upload', 'required': True}
if 'accept' in item:
if item.get('accept'):
tmp['accept'] = item['accept']
if 'size' in item:
if item.get('size'):
tmp['size'] = item['size']
dynamic_params.append(tmp)

View File

@ -187,9 +187,13 @@ class RemoteGit:
os.chmod(ask_file.name, 0o755)
env.update(GIT_SSH=ask_file.name)
command = f'git ls-remote -h {url} HEAD'
command = f'git ls-remote -h {url}'
res = subprocess.run(command, shell=True, capture_output=True, env=env)
return res.returncode == 0, res.stderr.decode()
if res.returncode == 0:
lines = res.stdout.decode().strip().split('\n')
branches = [x.split('/')[-1] for x in lines]
return True, branches
return False, res.stderr.decode()
def fetch_branches_tags(self):
body = f'set -e\ncd {self.path}\n'

View File

@ -1,12 +1,7 @@
apscheduler==3.7.0
Django==2.2.28
asgiref==3.2.10
channels==2.3.1
channels_redis==2.4.1
paramiko==2.11.0
django-redis==4.10.0
requests==2.22.0
GitPython==3.0.8
python-ldap==3.4.0
openpyxl==3.0.3
apscheduler==3.10.1
Django==4.2.2
paramiko==3.2.0
django-redis==5.2.0
requests==2.31.0
openpyxl==3.1.2
user_agents==2.2.0

View File

@ -16,8 +16,10 @@ import css from './index.module.less';
function Build(props) {
const [form] = Form.useForm()
const [tips, setTips] = useState()
const [branches, setBranches] = useState([])
useEffect(() => {
checkGit()
props.setHandler(() => handleSave)
if (credStore.records.length === 0) credStore.fetchRecords()
// eslint-disable-next-line react-hooks/exhaustive-deps
@ -27,6 +29,14 @@ function Build(props) {
const data = form.getFieldsValue()
if (!data.name) return message.error('请输入节点名称')
if (!data.condition) return message.error('请选择节点的执行条件')
if (!data.git_url) return message.error('请输入Git仓库地址')
if (!data.git_mode) return message.error('请选择构建分支/Tag')
if (data.git_mode === 'branch') {
if (!data.git_branch) return message.error('请选择构建分支')
if (!data.git_commit) return message.error('请选择构建分支规则')
} else if (!data.git_tag) {
return message.error('请选择构建Tag规则')
}
if (!data.target) return message.error('请选择构建主机')
if (!data.workspace) return message.error('请输入工作目录')
if (!data.command) return message.error('请输入构建命令')
@ -39,7 +49,9 @@ function Build(props) {
if (!data.git_url) return
http.post('/api/credential/check/', {id: data.credential_id, type: 'git', data: data.git_url})
.then(res => {
if (!res.is_pass) {
if (res.is_pass) {
setBranches(res.message)
} else {
setTips(res.message)
}
})
@ -88,6 +100,45 @@ function Build(props) {
<pre className={css.content}>{tips}</pre>
) : null}
</div>
<Form.Item required label="Git分支/Tag设置"
tooltip="最新提交指使用执行发布时最新的一次提交(或Tag),发布时选择会在执行发布时作为动态参数选择。">
<Input.Group compact>
<Form.Item name="git_mode" noStyle>
<Select style={{width: 100}} placeholder="请选择">
<Select.Option value="branch">分支</Select.Option>
<Select.Option value="tag">Tag</Select.Option>
</Select>
</Form.Item>
<Form.Item noStyle shouldUpdate>
{({getFieldValue}) =>
getFieldValue('git_mode') === 'branch' ? (
<React.Fragment>
<Form.Item name="git_branch" noStyle>
<Select style={{width: 200}} placeholder="请选择">
{branches.map(item => (
<Select.Option key={item} value={item}>{item}</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item name="git_commit" noStyle>
<Select style={{width: 150}} placeholder="请选择">
<Select.Option value="selective">发布时选择</Select.Option>
<Select.Option value="latest">最新提交</Select.Option>
</Select>
</Form.Item>
</React.Fragment>
) : (
<Form.Item name="git_tag" noStyle>
<Select style={{width: 200}} placeholder="请选择">
<Select.Option value="selective">发布时选择</Select.Option>
<Select.Option value="latest">最新提交</Select.Option>
</Select>
</Form.Item>
)
}
</Form.Item>
</Input.Group>
</Form.Item>
<Form.Item required name="target" label="构建主机">
<HostSelector onlyOne type="button"/>
</Form.Item>