团队, 我有这个函数可以根据登录选择 podtemplate,它可以工作,但我需要将其转换为不使用模板,而是使用 pod 规范进行动态代理调度。有什么提示我怎样才能实现它吗?一名代理人就能做到,但需要三名代理人才能做到,所以我陷入了困境。
def buildAgent() {
agent = 'artifacts'
if (params.Cuda) {
agent = 'artifacts-gpu'
}
if (params.'Image Targets'.contains('drive')) {
agent = 'artifacts-drive'
}
return agent
}
我对上述每个代理都有三个规格。我该如何更换它们?
artifacts
podSpec
apiVersion: v1
kind: Pod
metadata:
spec:
containers:
- name: argocd
image: image.com/third_party/argocd-jenkins-agent:2.2
command:
- cat
tty: true
volumeMounts:
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
hostNetwork: false
artifacts-gpu
podSpec
apiVersion: v1
kind: Pod
metadata:
spec:
.
.
artifacts-drive
podSpec
apiVersion: v1
kind: Pod
metadata:
spec:
.
.
单代理管道的工作原理如下,但我不确定如何处理多个代理。
pipeline {
agent {
kubernetes {
cloud 'ipp-stuff'
yaml '''
apiVersion: v1
kind: Pod
metadata:
spec:
'''
}
}
}
创建了一个变量 podYaml 并按如下方式使用它
podYaml= """
apiVersion: v1
kind: Pod
spec:
imagePullSecrets:
- name: repo-ecr
containers:
- name: main
image: test-verify:20220328135044
resources:
requests:
volumeMounts:
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
hostNetwork: false
"""
pipeline {
agent {
kubernetes {
cloud 'sc-prod'
yaml podYaml
}
}