Cloud Build无法使用Maven构建简单的构建步骤 [英] Cloud Build fails to build the the simple build step with maven
问题描述
测试云构建
我的 cloudbuild.yaml
- name: 'gcr.io/cloud-builders/mvn'
args: ['dockerfile:build']
dockerfile:build在bitbucket管道中完美运行,没问题.我用
dockerfile:build perfectly works in bitbucket pipeline, no problem. I use
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-version}</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>gcr.io/my-project-id/${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
但是通过这一步骤的云构建,我得到了错误:
But with the cloud-build for this single step I get the error:
[INFO] Step 14/15 : ARG JAR_FILE
[INFO]
[INFO] ---> Using cache
[INFO] ---> 55793de4bb9f
[INFO] [INFO] Step 15/15 : ADD target/${JAR_FILE} /usr/share/$SERVCE_FOLDER_NAME/app.jar
[INFO]
[ERROR] ADD failed: stat /mnt/cache/docker/tmp/docker-builder589658449/target/myappname-0.0.1-SNAPSHOT.jar: no such file or directory
(JAR_FILE是从maven dockerfile插件传递的
(the JAR_FILE is passed from the maven dockerfile plugin
没有此类文件或目录
为什么?.最后,我要调用dockerfile:build,并希望它与从另一个管道构建它时的样子相同.
Why?.. In the end of the day I juse call dockerfile:build and expect it to be the same as it is when I build it from another pipeline.
我的Dockerfile:
My Dockerfile:
FROM openjdk:8-jdk
ENV GOOGLE_APPLICATION_CREDENTIALS=/app/credentials.json
ARG ACTIVE_PROFILES=dev
ENV ACTIVE_PROFILES=$ACTIVE_PROFILES
ARG CREDENTIALS
ARG SERVCE_FOLDER_NAME=myappname-service
ENV SERVCE_FOLDER_NAME=$SERVCE_FOLDER_NAME
#ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/share/$SERVCE_FOLDER_NAME/app.jar"]
ENTRYPOINT ["./entrypoint.sh" ]
WORKDIR /app
EXPOSE 8080
COPY ./.gcloud/credentials.json credentials.json
COPY entrypoint.sh .
#Add Maven dependencies (not shaded into the artifact; Docker-cached)
#ADD target/lib /usr/share/$SERVCE_FOLDER_NAME/lib
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/$SERVCE_FOLDER_NAME/app.jar
EntryPoint脚本是(即日志中第15/15步中提到的脚本):
EntryPoint script is (that is what is mentioned on step 15/15 in the log):
java -Djava.security.egd=file:/dev/./urandom -jar /usr/share/$SERVCE_FOLDER_NAME/app.jar --spring.profiles.active=$ACTIVE_PROFILES
((我确实尝试过将硬编码的值传递给$ SERVCE_FOLDER_NAME,$ ACTIVE_PROFILES-相同[它在bitbucket管道中起作用)
(I did try to pass hard-coded values to $SERVCE_FOLDER_NAME, $ACTIVE_PROFILES - same [it works in bitbucket pipeline])
推荐答案
我想到了一些事情,
- 您如何触发构建?
- 手动使用gcloud或api?或自动使用构建触发器或github应用程序?
- how are you triggering the builds?
- manually with gcloud or api? or automatically with build triggers or the github app?
- 如果远程工作区位于您的.gitignore或.gcloudignore中,则它们可能不会获取目标目录或.jar文件.
- 尝试制作一个空的.gcloudignore或从.gitignore临时删除target/和.jar文件
- 相关链接: https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore , https://github.com/GoogleCloudPlatform/cloud-builders/issues/40
- the remote workspace might not be getting the target/ directory or .jar files if they are in your .gitignore or .gcloudignore
- try making an empty .gcloudignore or temporarily removing target/ and .jar files from .gitignore
- relevant links: https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore, https://github.com/GoogleCloudPlatform/cloud-builders/issues/40
- https://cloud.google.com/cloud-build /docs/build-debug-locally
- https://github.com/GoogleCloudPlatform/cloud-build-local
- https://cloud.google.com/cloud-build/docs/build-debug-locally
- https://github.com/GoogleCloudPlatform/cloud-build-local
这篇关于Cloud Build无法使用Maven构建简单的构建步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!