我是CI / CD的新手,现在正尝试使用Gitlab CI / CD功能在Gitlab存储库中部署Maven Java项目。如果将其部署到内置Docker映像,则部署步骤将成功。但是,当我尝试在本地计算机目标中进行部署时,部署步骤将失败。有人对此有任何想法吗?
我已经尝试在Mac OSX中注册并运行gitlab-runner来处理CI / CD。我已经安装了Docker。
这是.gitlab-ci.yml文件。
image: maven:latest
stages:
- build
- test
- deploy
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
SSH_PRIVATE_KEY: "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAA..."
SSH_KNOWN_HOSTS: "# YmkSun.local:22 SSH-2.0-OpenSSH_7.9
ymksun.local ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSMOpRI..."
DEPLOY_USER: "yemyokyaw"
DEPLOY_HOST: "YmkSun.local"
DEPLOY_PATH: "/Users/yemyokyaw/Documents/tmp"
cache:
paths:
- .m2/repository/
- target/
build_app:
stage: build
dependencies: []
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
deploy:stand:
stage: deploy
dependencies: []
environment:
name: staging
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r'
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh yemyokyaw@YmkSun.local "cd /builds/ymksun/sample-cicd-parent && git checkout master && git pull origin master && exit"
- ssh $DEPLOY_USER@$DEPLOY_HOST "cd '$DEPLOY_PATH'; git pull; docker restart home-assistant"
尝试第二个脚本时出现错误消息:
$ ssh $ DEPLOY_USER @ $ DEPLOY_HOST“ cd'$ DEPLOY_PATH'; git pull; docker 重新启动家庭助理” ssh:连接到主机本地主机端口22:无法 分配请求的地址
尝试第一个脚本时出现错误消息:
$ ssh yemyokyaw@YmkSun.local“ cd / builds / ymksun / sample-cicd-parent && git checkout master && git pull origin master && exit”主机密钥验证失败。