如何将Gitlab CI_JOB_TOKEN传递到AWS Elasticbeanstalk单容器Docker环境

时间:2020-05-18 19:57:10

标签: docker gitlab dockerfile amazon-elastic-beanstalk gitlab-ci

我有一个运行在运行Java应用程序的Docker单一容器上的elasticbeanstalk环境。

这是我的Dockerfile。

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <servers>
    <server>
      <id>gitlab-maven</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Job-Token</name>
            <value>${env.CI_JOB_TOKEN}</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>

</settings>

settings.xml

deploy-docker:
  stage: deploy-docker
  image:
    name: circleci/python:3.7.6-buster
  script: |
    sudo pip install awsebcli --upgrade
    eb use staging-dockerization
    eb setenv CI_JOB_TOKEN=$CI_JOB_TOKEN
    eb deploy

和Elasticbeanstalk的配置如下。

Caused by: org.apache.maven.project.DependencyResolutionException: 
Could not resolve dependencies for project com.main:app:jar:1.0: 
Failed to collect dependencies at com.main:app-lib:jar:0.0.1
....

Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: 
Could not transfer artifact com.main:app-lib:pom:0.0.1 
from/to gitlab-maven (https://gitlab.com/api/v4/groups/XXXXXX/-/packages/maven): 

Authentication failed for
https://gitlab.com/api/v4/groups/XXXXXX/-/packages/maven/com/main/app-lib/0.0.1/app-lib-0.0.1.pom 401 Unauthorized
....

The command 'mvn -X clean package -s .m2/settings.xml' returned a non-zero code: 1

但是构建失败。

CI_JOB_TOKEN

由于无法解析settings.xml所需要的CI_JOB_TOKEN,因此无法下载构建所需的Gitlab maven软件包。关于如何通过{{1}}来完成这项工作的任何建议。

0 个答案:

没有答案