[英]How to configure a Jenkinsfile to build docker image and push it to a private registry
我有兩個問題。 但是也許我不知道如何為這個問題添加標簽,所以我為這兩個標簽都添加了標簽。 第一個問題是有關詹金斯插件使用烘烤和使用推泊塢窗圖像此 。 以下是我的Jenkinsfile腳本。 我完成了在目標目錄中構建jar文件的操作。 然后我要運行此docker插件以使用此工件進行烘焙。 如您所知,我們需要有一個Dockerfile,因此我將其放在git克隆源代碼的根目錄中。 我該如何配置? 我不知道該怎么做。 如果我在下面跑,詹金斯告訴我沒有任何步驟。
pipeline {
agent any
stages {
stage('build') {
steps {
git branch: 'master', credentialsId: 'e.joe-gitlab', url: 'http://70.121.224.108/gitlab/cicd/spring-petclinic.git'
sh 'mvn clean package'
}
}
stage('verify') {
steps {
sh 'ls -alF target'
}
}
stage('build-docker-image') {
steps {
docker.withRegistry('https://sds.redii.net/', 'redii-e.joe') {
def app = docker.build("sds.redii.net/e-joe/spring-pet-clinic-demo:v1",'.')
app.push()
}
}
}
}
}
更新,這是另一個Jenkins管道語法嗅探器生成器。 但這也不起作用。
pipeline {
agent any
stages {
stage('build') {
steps {
git branch: 'master', credentialsId: 'e.joe-gitlab', url: 'http://70.121.224.108/gitlab/cicd/spring-petclinic.git'
sh 'mvn clean package'
}
}
stage('verify') {
steps {
sh 'ls -alF target'
}
}
stage('docker') {
withDockerRegistry([credentialsId: 'redii-e.joe', url: 'https://sds.redii.net']) {
def app = docker.build("sds.redii.net/e-joe/spring-pet-clinic-demo:v1",'.')
app.push()
}
}
}
}
Dokerfile如下所示。 如果我嘗試在本地烘烤圖像,則會出現以下錯誤。
container_linux.go:247: starting container process caused "chdir to cwd (\"/usr/myapp\") set in config.json failed: not a directory"
oci runtime error: container_linux.go:247: starting container process caused "chdir to cwd (\"/usr/myapp\") set in config.json failed: not a directory"
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Docker文件
FROM openjdk:7
COPY ./target/spring-petclinic-1.5.1.jar /usr/myapp
WORKDIR /usr/myapp
RUN java spring-petclinic-1.5.1.jar
您正在將.jar寫入/usr/myapp
。 這意味着/usr/myapp
將是jar文件而不是目錄,從而導致該錯誤。 將您的COPY ./target/spring-petclinic-1.5.1.jar /usr/myapp/
復制行更改為COPY ./target/spring-petclinic-1.5.1.jar /usr/myapp/
(帶有斜杠),您的Dockerfile應該可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.