gpt4 book ai didi

docker - Jenkins Kubernetes 插件 : How to build image from Dockerfile and run steps inside the image

转载 作者:行者123 更新时间:2023-12-02 11:37:21 26 4
gpt4 key购买 nike

我正在使用 Jenkins kubernetes-plugin .是否可以从 Dockerfile 构建 docker 镜像,然后在创建的镜像中运行步骤?该插件需要在 pod 模板中指定一个图像,所以我的第一次尝试是使用 docker-in-docker 但步骤 docker.image('jenkins/jnlp-slave').inside() {..}失败:

pipeline {
agent {
kubernetes {
//cloud 'kubernetes'
label 'mypod'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: docker
image: docker:1.11
command: ['cat']
tty: true
volumeMounts:
- name: dockersock
mountPath: /var/run/docker.sock
volumes:
- name: dockersock
hostPath:
path: /var/run/docker.sock
"""
}
}
stages {
stage('Build Docker image') {
steps {
git 'https://github.com/jenkinsci/docker-jnlp-slave.git'
container('docker') {
sh "docker build -t jenkins/jnlp-slave ."
docker.image('jenkins/jnlp-slave').inside() {
sh "whoami"
}
}
}
}
}
}

失败:
WorkflowScript: 31: Expected a symbol @ line 31, column 11.
docker.image('jenkins/jnlp-slave').inside() {

最佳答案

正如马特在评论中指出的那样,这是有效的:

pipeline {
agent {
kubernetes {
//cloud 'kubernetes'
label 'mypod'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: docker
image: docker:1.11
command: ['cat']
tty: true
volumeMounts:
- name: dockersock
mountPath: /var/run/docker.sock
volumes:
- name: dockersock
hostPath:
path: /var/run/docker.sock
"""
}
}
stages {
stage('Build Docker image') {
steps {
git 'https://github.com/jenkinsci/docker-jnlp-slave.git'
container('docker') {
script {
def image = docker.build('jenkins/jnlp-slave')
image.inside() {
sh "whoami"
}
}
}
}
}
}
}

关于docker - Jenkins Kubernetes 插件 : How to build image from Dockerfile and run steps inside the image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54764445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com