大家好,谁正在阅读这篇文章!我有一个测试java应用程序,包含:
kafka = new KafkaContainer(
DockerImageName.parse("harbor-main.test.com/devbird/confluentinc/cp-kafka:7.3.2")
.asCompatibleSubstituteFor("confluentinc/cp-kafka")
kafka.withEmbeddedZookeeper().start();
...
我在Jenkins中使用Maven容器构建的。
mvn clean install
我正在使用Jenkins,在Kubernetes中运行。
代理文件,用于Jenkinsfile
apiVersion: v1
kind: Pod
metadata:
namespace: project-jenkins
spec:
containers:
- name: maven
image: harbor-main.test.com/maven-jdk17-git:latest
command:
- cat
tty: true
volumeMounts:
- name: maven-cache
mountPath: /root/.m2/repository
- name: dind-daemon
image: harbor-main.test.com/docker:dind-rootless
securityContext:
privileged: true
readOnlyRootFilesystem: false
command:
- cat
tty: true
volumeMounts:
- name: docker-socket
mountPath: /run/user/1001/docker.sock
volumes:
- name: docker-socket
emptyDir: {}
- name: maven-cache
persistentVolumeClaim:
claimName: maven-cache
我在Jenkins中得到错误:
08:12:51 23/03/16 08:12:51 WARN TestcontainersConfiguration: Attempted to read Testcontainers configuration file at file:/root/.testcontainers.properties but the file was not found. Exception message: FileNotFoundException: /root/.testcontainers.properties (No such file or directory)
08:12:52 23/03/16 08:12:51 ERROR DockerClientProviderStrategy: Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
08:12:52 UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)As no valid configuration was found, execution cannot continue.
08:12:52 See https://www.testcontainers.org/on_failure.html for more details.
08:12:52 Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.228 sec <<< FAILURE!
我是否遗漏了一些额外的测试容器配置?
我的代理文件是否正确?
1条答案
按热度按时间deikduxw1#
我就能找出问题所在。
所以工作方案是:
在测试中:
在Jenkins管道中(在maven容器中):
src/main/resources/. www.example.com文件的内容testcontainers.properties:
Jenkins代理yaml文件:
在我的例子中,userID是1000。你可以使用命令获取它:
我花了几天时间来解决它,希望有人会发现它有用。