0

So I asked question before about merging gitlub runner into remote branch, but I have made a lot of changes since then. The whole idea behind what I want is that I have a simple script which creates Excel file on runner and I want to push whole runner into a branch. I managed to add SSH key to my runner and I don't get any errors with it so I guess it's ok, but I get the error when I try to push from runner to my remote branch. The error I get is:

Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I think It may be a problem with a way that I push or something. Right now my pushing job is a little bit of a frankenstein created from parts from other threads on stack. The whole code:

variables:
  GIT_STRATEGY: clone
build-job:
  stage: build
  tags:
    - example_repo
  before_script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$GIT_SSH_PRIV_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$GIT_SSH_PRIV_KEY" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - echo SSH added
  script:
    - echo "Hello!"
    - ls
    - python3 -V
    - pip3 list

test-job1:
  stage: test
  tags:
    - example_repo
  script:
    - python3 Experiments/ConfigAutomation.py

test-job2:
  stage: test
  tags:
    - example_repo
  script:
    - git config user.email "[email protected]"
    - git config user.name "username"
    - git checkout -b ci_processing
    - git show-ref
    - git remote -v
    - git remote set-url --push origin git@gitlab/example_repo.git
    - git add .
    - git commit --amend --reset-author --allow-empty -m "Files from runner to branch"
    - git push origin ci_processing:automation-test || true
    - echo "Pushed"

deploy-prod:
  stage: deploy
  tags:
    - example_repo
  script:
    - echo "This job deploys something."

close-conn:
  stage: .post
  tags:
    - example_repo
  script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - eval '/usr/bin/ssh-agent -k'

3
  • stackoverflow.com/… Commented Oct 5, 2021 at 11:50
  • The problem is about host key, not user key. Instead of echo "$GIT_SSH_PRIV_KEY" >> ~/.ssh/known_hosts the command must be ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts. Also check the command git remote set-url --push origin git@gitlab/example_repo.git — are you sure the host is just gitlab, not gitlab.com? Commented Oct 5, 2021 at 11:52
  • @phd I changed as you said and I don't get the error thanks! The url that I have given is only example because I can't share the right one. It's 100% alright, but the file still isn't pushed to my remote repo. Commented Oct 5, 2021 at 11:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.