Jenkinsfile抛出Docker:在jenkins上找不到docker在docker上的ci/cd of spring boot项目

问题描述 投票:0回答:1
groovy脚本,用于编程创建Jenkins Pipeline作业。

Jenkins Dockerfile安装Docker CLI。 Docker构成定义

    服务,包括詹金斯及其依赖。 Jenkinsfile,
  • 使用Docker为项目构建Docker映像。
  • 注:
  • 当我与Windows一起工作时,我更改为
  • /var/run/docker.sock:/var/run/docker.sock
  • 检测管道中的testContainer。否则我将无法集成。

here是下面显示的groovy文件。

/var/run/docker.sock.raw:/var/run/docker.sock
here是
plugin.txt

import hudson.plugins.git.UserRemoteConfig import hudson.plugins.git.BranchSpec import hudson.plugins.git.GitSCM import jenkins.model.* import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition def instance = Jenkins.getInstance() def jobName = "flightsearchapi" def job = instance.getItem(jobName) if (job != null) { job.delete() } def pipelineJob = instance.createProject(org.jenkinsci.plugins.workflow.job.WorkflowJob, jobName) def definition = new CpsScmFlowDefinition( new GitSCM( [ new UserRemoteConfig("https://github.com/Rapter1990/flightsearchapi.git", null, null, null) ], [new BranchSpec("*/development/issue-2/implement-jenkins-for-ci-cd")], false, Collections.emptyList(), null, null, Collections.emptyList() ), "Jenkinsfile" ) definition.setLightweight(true) pipelineJob.setDefinition(definition) pipelineJob.save() println("Pipeline job '${jobName}' has been successfully created!")

在下
workflow-aggregator
git
job-dsl
ws-cleanup
docker-plugin
docker-workflow
docker-commons

HERCE是docker-compose.yml

FROM jenkins/jenkins:lts

# Plugin list
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli --plugin-file /usr/share/jenkins/ref/plugins.txt

# For Groovy scripts, init.d directory
COPY init.groovy.d/ /var/jenkins_home/init.groovy.d/

# Install Docker CLI
USER root
RUN apt-get update && apt-get install -y docker.io

下面显示的jenkinsfile

version: '3.9' services: jenkins: build: context: . dockerfile: Dockerfile container_name: jenkins-server ports: - "8080:8080" # Expose Jenkins UI on port 8080 - "50000:50000" # Expose port for Jenkins agents volumes: - jenkins_home:/var/jenkins_home # Persistent Jenkins data - /var/run/docker.sock.raw:/var/run/docker.sock # Mount Docker socket for Docker builds - ../k8s:/var/jenkins_home/k8s # Mount Kubernetes configuration files (optional) - ./init.groovy.d:/var/jenkins_home/init.groovy.d # Mount Jenkins init scripts (optional) environment: JAVA_OPTS: "-Djenkins.install.runSetupWizard=false" # Skip setup wizard (optional) user: root # Run as root to allow installing dependencies volumes: jenkins_home:
在管道中,我试图作为CI/CD进程的一部分构建和推动Docker映像,但是错误消息显示

pipeline { agent { docker { image 'maven:3.9.9-amazoncorretto-21-alpine' args '-v /root/.m2:/root/.m2' } } environment { GIT_REPO_URL = 'https://github.com/Rapter1990/flightsearchapi.git' BRANCH_NAME = 'development/issue-2/implement-jenkins-for-ci-cd' DOCKERHUB_USERNAME = 'noyandocker' DOCKER_IMAGE_NAME = 'flightsearchapi-jenkins' } stages { stage('Checkout') { steps { script { checkout([ $class: 'GitSCM', branches: [[name: "*/${env.BRANCH_NAME}"]], userRemoteConfigs: [[url: "${env.GIT_REPO_URL}"]] ]) } } } stage('Build') { steps { sh 'mvn clean install' } } stage('Build Docker Image') { steps { sh "docker build -t ${env.DOCKERHUB_USERNAME}/${env.DOCKER_IMAGE_NAME}:latest ." } } stage('Push Docker Image') { steps { withDockerRegistry([credentialsId: 'docker-hub-credentials', url: '']) { sh "docker push ${env.DOCKERHUB_USERNAME}/${env.DOCKER_IMAGE_NAME}:latest" } } } } post { always { cleanWs(cleanWhenNotBuilt: false, deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true, patterns: [[pattern: '.gitignore', type: 'INCLUDE'], [pattern: '.propsfile', type: 'EXCLUDE']]) } } } 您可以解决这个问题吗?

	

在我遵循下面显示的这些步骤之后,该问题消失了。 1)

将代理更改为docker image

2)

为其相关步骤定义MVN的构建步骤和Docker
这里是下面显示的代码。
+ docker build -t noyandocker/flightsearchapi-jenkins:latest . /var/jenkins_home/workspace/flightsearchapi@tmp/durable-7294ca4e/script.sh.copy: line 1: docker: not found

docker jenkins docker-compose jenkins-pipeline
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.