我正在使用在线Gitlab CI,Kubernetes和docker建立云DevOps部署管道。我正在关注Continous delivery of a spring boot application with Gitlab CI and kubernetes和Kubectl delete/create secret forbidden (Google cloud platform)上的示例帖子。
在我的.gitlab-ci.yml文件的源代码下面找到
@GenericGenerator(name = "sequence_gen", strategy = "sequence")
@CollectionId(columns = { @Column(name="HOBBY_ID") }, generator = "sequence_gen", type = @Type(type="long"))
private Collection<HobbyDetails> hobbies = new ArrayList<HobbyDetails>();
部署在以下行失败
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
SPRING_PROFILES_ACTIVE: gitlab-ci
stages:
- build
- package
- deploy
maven-build:
image: maven:3-jdk-8
stage: build
script: "mvn package -B"
artifacts:
paths:
- target/*.jar
docker-build:
stage: package
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker build -t registry.gitlab.com/username/mta-hosting-optimizer .
- docker push registry.gitlab.com/username/mta-hosting-optimizer
k8s-deploy:
image: google/cloud-sdk
stage: deploy
script:
- echo "$GOOGLE_KEY" > key.json
- gcloud auth activate-service-account --key-file key.json
- gcloud config set compute/zone europe-west1-c
- gcloud config set project mta-hosting-optimizer
- gcloud config unset container/use_client_certificate
- gcloud config set container/use_client_certificate True
- gcloud container clusters get-credentials mta-hosting-optimizer
- kubectl create -f admin.yaml --validate=false
- kubectl create clusterrolebinding serviceaccounts-cluster-admin--clusterrole=cluster-admin --group=system:serviceaccounts
- kubectl delete secret registry.gitlab.com
- kubectl create secret docker-registry registry.gitlab.com --docker-server=https://registry.gitlab.com --docker-username=username --docker-password=$REGISTRY_PASSWD --docker-email=email@email.com
- kubectl apply -f deployment.yml
此失败时显示的错误消息如下:
- kubectl create -f admin.yaml --validate=false
admin.yaml文件的来源如下:
error: error converting YAML to JSON: yaml: mapping values are not allowed in this context
ERROR: Job failed: exit code 1
找到Maven构建和Docker构建/打包阶段。这是唯一失败的阶段。我将感谢每个人在解决此问题方面的帮助。 非常感谢。
答案 0 :(得分:1)
您有YAML验证错误。这意味着您的YAML格式不正确。
您最有可能希望通过以下方式格式化int noConnection() { return _noConnection; }
void lostConnection() { _noConnection = 1; myFunction(); }
文件:
admin.yaml
也:由于Matthew L Daniel已经pointed out,您不应该禁用YAML文件的验证。