发布于2021-05-29 22:40 阅读(861) 评论(0) 点赞(6) 收藏(5)
代理就是 Jenkins 干活的地方,就是你准备让Jenkins 在那个地方完成你给它设定的任务。
代理可以安装 Jenkins 的服务器(自己),通常成为 master, 也可以是一个 slave, 也可以是一个Docker 的容器,还可以是一个 kubernetes 的 Pod.
在 Pipeline 中设置代理的方式式通过 agent
声明
agent
出现在 pipeline
块内的顶层,就是全局代理。这是必须要设置的。全局代理边上此 jenkinsfile 中的所有阶段都将在此代理中执行。
出现在 stage
块中,就是阶段代理。
阶段代理只作用与此阶段。
例如: agent any
pipeline {
agent any
stages {
...
}
}
pipeline {
agent { label "node1"}
stages {
...
}
}
参数
为了支持作者可能有的各种各样的用例流水线, agent 部分支持一些不同类型的参数。这些参数应用在pipeline
块的顶层, 或 stage 指令内部。
any
在任何可用的代理上执行流水线或阶段。例如: agent any
none
当在 pipeline 块的顶部没有全局代理, 该参数将会被分配到整个流水线的运行中并且每个 stage 部分都需要包含他自己的 agent 部分。比如: agent none
label
在提供了标签的 Jenkins 环境中可用的代理上执行流水线或阶段。 例如: agent { label ‘my-defined-label’ }
node
agent { node { label ‘labelName’ } } 和 agent { label ‘labelName’ } 一样, 但是 node 允许额外的选项 (比如 customWorkspace )。
docker
使用给定的容器执行流水线或阶段。该容器将在预置的 node上,或在匹配可选定义的label
参数上,动态的供应来接受基于Docker的流水线。 docker 也可以选择的接受 args 参数,该参数可能包含直接传递到 docker run 调用的参数, 以及 alwaysPull 选项, 该选项强制 docker pull ,即使镜像名称已经存在。 比如: agent { docker ‘maven:3-alpine’ } 或
agent {
docker {
image 'maven:3-alpine'
label 'my-defined-label'
args '-v /tmp:/tmp'
}
}
kubernetes
需要 kubernetes plugin
在部署在Kubernetes集群上的pod内执行管道或stage。要使用此选项,必须从多分支管道或SCM管道加载Jenkinsfile。Pod模板是在kubernetes{}块中定义的。例如,如果您想要一个内有一个Kaniko容器的pod,您可以将其定义为:
agent {
kubernetes {
label podlabel
yaml """
kind: Pod
metadata:
name: jenkins-agent
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
imagePullPolicy: Always
command:
- /busybox/cat
tty: true
volumeMounts:
- name: aws-secret
mountPath: /root/.aws/
- name: docker-registry-config
mountPath: /kaniko/.docker
restartPolicy: Never
volumes:
- name: aws-secret
secret:
secretName: aws-secret
- name: docker-registry-config
configMap:
name: docker-registry-config
"""
}
/**
* This pipeline will build and deploy a Docker image with Kaniko
* https://github.com/GoogleContainerTools/kaniko
* without needing a Docker host
*
* You need to create a jenkins-docker-cfg secret with your docker config
* as described in
* https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-in-the-cluster-that-holds-your-authorization-token
*/
podTemplate(yaml: """
kind: Pod
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug-539ddefcae3fd6b411a95982a830d987f4214251
imagePullPolicy: Always
command:
- /busybox/cat
tty: true
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /kaniko/.docker
volumes:
- name: jenkins-docker-cfg
projected:
sources:
- secret:
name: regcred
items:
- key: .dockerconfigjson
path: config.json
"""
) {
node(POD_LABEL) {
stage('Build with Kaniko') {
git 'https://github.com/jenkinsci/docker-inbound-agent.git'
container('kaniko') {
sh '/kaniko/executor -f `pwd`/Dockerfile -c `pwd` --insecure --skip-tls-verify --cache=true --destination=mydockerregistry:5000/myorg/myimage'
}
}
}
}
原文链接:https://blog.csdn.net/qq_22648091/article/details/116865236
作者:skdk
链接:http://www.javaheidong.com/blog/article/207670/9287b400f608df8442eb/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!