crtxdmp.

A collection of ideas, snippets and other things.


Push to git repo via gitlab pipeline

  • Create deploy key via Your Project --> Settings -> Repository
    • Grant write permission
  • Create CI variables via Your Project --> Settings --> CI/CD
    • CI_EMAIL with the E-Mail address which should push
    • CI_USERNAME with the Username which should push
    • CONTENT_FETCH_AND_PUSH_KEY with the private key of the deploy key
    • CONTENT_FETCH_AND_PUSH_KEY_PUBLIC with the public key of the deploy key
File: .gitlab-ci.yml
refresh content:
  stage: prepare
  variables:
    BRANCH_NAME: "my-branch"
  before_script:
    - 'which ssh-agent || ( apt-get update -qy && apt-get install openssh-client -qqy )'
    - eval `ssh-agent -s`
    - echo "${CONTENT_FETCH_AND_PUSH_KEY}" | tr -d '\r' | ssh-add - > /dev/null # add ssh key
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "CONTENT_FETCH_AND_PUSH_KEY_PUBLIC" >> ~/.ssh/id_rsa.pub
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
    - git config --global user.email "${CI_EMAIL}"
    - git config --global user.name "${CI_USERNAME}"
    - git remote rm origin && git remote add origin [email protected]:$CI_PROJECT_PATH.git
    - git fetch --all --prune
    - git checkout origin/production
    - echo "-------------------- Git setup done --------------------"
    - echo "do some stuff" > somefile
    - touch somefile
    - git add .
    - git commit -m "Refresh content"
    - git push origin HEAD:$BRANCH_NAME

, — Apr 1, 2021