我的图书馆托管在Google云存储上。我正在使用Jenkins将我的应用程序部署到GKE中。
我正在使用CloudStorageMaven库(V1.0)将项目推送到GCS。
我能够部署我的库项目,但是,当我尝试在Jenkins服务器上运行微服务测试时,maven无法下载我的库。
我尝试将GCS存储桶公开,但没有任何区别。
Jenkinsfile
#!/usr/bin/env groovy
podTemplate(
label: 'slavepod',
containers: [
containerTemplate (
name: 'maven',
image: 'maven:3.5.2-alpine',
command: 'cat',
ttyEnabled: true,
resourceRequestCpu: '256m',
resourceLimitCpu: '512m',
resourceRequestMemory: '512Mi',
resourceLimitMemory: '1024Mi'
),
containerTemplate (
name: 'docker',
image: 'gcr.io/cloud-builders/docker',
command: 'cat',
ttyEnabled: true,
resourceRequestCpu: '512m',
resourceLimitCpu: '1024m',
resourceRequestMemory: '512Mi',
resourceLimitMemory: '1024Mi'
),
containerTemplate (
name: 'kubectl',
image: 'gcr.io/cloud-builders/kubectl',
command: 'cat',
ttyEnabled: true,
resourceRequestCpu: '512m',
resourceLimitCpu: '1024m',
resourceRequestMemory: '512Mi',
resourceLimitMemory: '1024Mi'
),
containerTemplate (
name: 'gcloud',
image: 'gcr.io/cloud-builders/gcloud',
command: 'cat',
ttyEnabled: true,
resourceRequestCpu: '512m',
resourceLimitCpu: '1024m',
resourceRequestMemory: '512Mi',
resourceLimitMemory: '1024Mi'
)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
persistentVolumeClaim(claimName: 'maven-repo', mountPath: '/home/jenkins/.m2')
]
)
{
node('slavepod') {
stage('Clone repository') {
checkout scm
}
stage('Unit Test') {
container('maven') {
echo 'Running Maven tests'
sh("mvn -Dmaven.repo.local=/home/jenkins/.m2/ test")
}
}
} // end of pipeline
我在pom.xml中配置了扩展名和存储库
<build>
....
<extensions>
<extension>
<groupId>com.gkatzioura.maven.cloud</groupId>
<artifactId>google-storage-wagon</artifactId>
<version>1.0</version>
</extension>
</extensions>
</build>
<repositories>
<repository>
<id>ca.performance.common</id>
<url>gs://performance-repository</url>
</repository>
</repositories>
我在Jenkins管道控制台中遇到的错误如下:
Downloading from ca.performance.common: gs://url/to/repository/jar-1.0.0.pom
[ERROR] Could not establish connection with google cloud
com.google.cloud.storage.StorageException: Insufficient Permission
at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate (HttpStorageRpc.java:219)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.list (HttpStorageRpc.java:314)
at com.google.cloud.storage.StorageImpl$6.call (StorageImpl.java:272)
at com.google.cloud.storage.StorageImpl$6.call (StorageImpl.java:269)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit (DirectRetryingExecutor.java:89)
at com.google.cloud.RetryHelper.run (RetryHelper.java:74)
at com.google.cloud.RetryHelper.runWithRetries (RetryHelper.java:51)
at com.google.cloud.storage.StorageImpl.listBuckets (StorageImpl.java:268)
at com.google.cloud.storage.StorageImpl.list (StorageImpl.java:257)
at com.gkatzioura.maven.cloud.gcs.GoogleStorageRepository.connect (GoogleStorageRepository.java:55)
at com.gkatzioura.maven.cloud.gcs.GoogleStorageWagon.connect (GoogleStorageWagon.java:135)
at org.eclipse.aether.transport.wagon.WagonTransporter.connectWagon (WagonTransporter.java:342)
at org.eclipse.aether.transport.wagon.WagonTransporter.pollWagon (WagonTransporter.java:382)
at org.eclipse.aether.transport.wagon.WagonTransporter.execute (WagonTransporter.java:431)
at org.eclipse.aether.transport.wagon.WagonTransporter.get (WagonTransporter.java:412)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$GetTaskRunner.runTask (BasicRepositoryConnector.java:453)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run (BasicRepositoryConnector.java:360)
at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run (RunnableErrorForwarder.java:75)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$DirectExecutor.execute (BasicRepositoryConnector.java:583)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector.get (BasicRepositoryConnector.java:259)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads (DefaultArtifactResolver.java:498)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve (DefaultArtifactResolver.java:399)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts (DefaultArtifactResolver.java:224)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact (DefaultArtifactResolver.java:201)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom (DefaultArtifactDescriptorReader.java:261)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor (DefaultArtifactDescriptorReader.java:192)
at org.eclipse.aether.internal.impl.DefaultDependencyCollector.resolveCachedArtifactDescriptor (DefaultDependencyCollector.java:539)
at org.eclipse.aether.internal.impl.DefaultDependencyCollector.getArtifactDescriptorResult (DefaultDependencyCollector.java:522)
at org.eclipse.aether.internal.impl.DefaultDependencyCollector.processDependency (DefaultDependencyCollector.java:411)
at org.eclipse.aether.internal.impl.DefaultDependencyCollector.processDependency (DefaultDependencyCollector.java:365)
at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process (DefaultDependencyCollector.java:353)
at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies (DefaultDependencyCollector.java:256)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.collectDependencies (DefaultRepositorySystem.java:282)
at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve (DefaultProjectDependenciesResolver.java:169)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies (LifecycleDependencyResolver.java:223)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies (LifecycleDependencyResolver.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved (MojoExecutor.java:246)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:200)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Insufficient Permission",
"reason" : "insufficientPermissions"
} ],
"message" : "Insufficient Permission"
}
答案 0 :(得分:0)
您是否遵循发布的CloudStorageMaven链接中的full guide中的说明?
“下一步是最关键的,这与 验证到Google Cloud。
您需要在系统中设置gcloud命令行,然后 必须使用具有以下权限的帐户发布登录名“ gcloud auth login –brief” 访问我们之前创建的存储桶。另一种方法是使用 GOOGLE_APPLICATION_CREDENTIALS环境变量。您可以使用 这个GOOGLE_APPLICATION_CREDENTIALS,以便为您设置路径 谷歌应用程序凭据文件。凭证文件还应该 能够访问我们之前创建的存储桶。”
如果是,您采取了什么步骤使GCS存储桶可公开访问?如official docs所述,您需要向特定用户授予足够的权限,或允许存储桶级的公共(allUsers)可读性,以使给定存储桶中的所有对象可访问指定用户或allUsers。
尝试中的错误代码指向访问权限问题:
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Insufficient Permission",
"reason" : "insufficientPermissions"
} ],
"message" : "Insufficient Permission"
}
如果您还没有尝试过,可以通过运行以下命令在存储桶级别上grant the allUsers access:
$ gsutil iam ch allUsers:objectViewer gs://[BUCKET_NAME]
但是,按照最佳实践,我建议只在存储桶级别为希望对给定存储桶中的对象具有读/写访问权限的用户帐户或服务帐户授予细化访问权限。您可以详细了解如何here。
希望这会有所帮助!