在您的 .gitlab-ci.yml 中发现错误:根配置包含未知键:部署脚本环境
2020-05-05
12033
提交以下 .yml 文件时出现以下错误:
Found errors in your .gitlab-ci.yml: root config contains unknown keys: deploy script environment
variables:
MAVEN_CLI_OPTS: " -s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
- target/
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
deploy:
stage: production
before_script:
- mkdir -p ~/.ssh
- echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- bash ./gitlab-deploy/.gitlab-deploy.prod.sh
environment:
name: production
url: http://myurl.com:81
我正在尝试将 Maven 项目从 GitLab 部署到 AWS EC2。 请检查。
3个回答
检查你的缩进。它应该是这样的
deploy:
stage: production
before_script:
- mkdir -p ~/.ssh
- echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- bash ./gitlab-deploy/.gitlab-deploy.prod.sh
environment:
name: production
url: http://myurl.com:81
Jack
2021-01-13
仔细检查你的
deploy
作业,此行看起来很可疑:
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
看到那里有一个单引号吗?
Aleksey Tsalolikhin
2020-05-05
在您的“部署”作业中,尝试将“before_script”更改为“script”。为什么要配置“before_script”部分而不配置“script”?
Samir Ibbou
2020-08-03