Home > OS >  How do I push commit to different repo from within a gitlab CI pipeline?
How do I push commit to different repo from within a gitlab CI pipeline?

Time:11-17

I want to push my commit from repository to different repository in deploy stage but I did not do it.


deploy-job:      
  stage: deploy  
  before_script:
    - 'which ssh-agent || ( apt-get update -qy && apt-get install openssh-client -qqy )'
    - eval `ssh-agent -s`
    - echo ${SSH_PRIVATE_KEY}
    - echo ${SSH_PRIVATE_KEY}
    ## Create the SSH directory and give it the right permissions
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_PUBLIC_KEY" >> ~/.ssh/id_rsa.pub
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  script:
    - git branch -a    
    - git config --global user.email "${CI_EMAIL}"
    - git config --global user.name "${CI_USERNAME}"
    - git add .  
    - git commit -m "Compiled PDF from $CI_COMMIT_SHORT_SHA [skip ci]" || echo "No changes, nothing to commit!"
    - git remote rm origin && git remote add origin http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git
    - git branch -a
    - git push -f -u origin main

But I take this error:

To http://ip:3000/username/first_exe.git
 ! [remote rejected] main -> main (shallow update not allowed)
error: failed to push some refs to 'http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git' 

What is the problem?

Thanks.

CodePudding user response:

GitLab allows to perform shallow cloning the repositories and you need to overcome it by doing git fetch.

Just run this before you do push.

git fetch --unshallow || git fetch --all

CodePudding user response:

I tried it but I took this output.

$ git branch -a
* (HEAD detached from 0cd8e98)
$ git fetch --unshallow || git fetch --all
warning: no common commits
From http://10.110.10.15:3000/USERNAME/first_exe
 * [new branch]      x_branch -> origin/x_branch
 * [new branch]      main           -> origin/main
$ git push -f -u origin main
error: src refspec main does not match any.
error: failed to push some refs to 'http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git' 
ERROR: Job failed: exit code 1
  • Related