If you are using the Shell executor and not Docker, it is easier to set up an That’s it! You can now have access to private servers or repositories in yourīuild environment. ![]() If you are accessing a private GitLab repository you must add Step to the services that you want to have an access to from inside the buildĮnvironment. Īs a final step, add the public key from the one you created in the first.Make sure the private server’s SSH host keys are verified. The before_script can be set as a default # - git config -global user.email # - git config -global user.name "User name" # (change apt-get to yum if you use an RPM-based image) # - ' command -v ssh-agent >/dev/null || ( apt-get update -y & apt-get install openssh-client -y )' # Run ssh-agent (inside the build environment) # - eval $(ssh-agent -s) # Give the right permissions, otherwise ssh-add will refuse to add files # Add the SSH key stored in SSH_PRIVATE_KEY file type CI/CD variable to the agent store # - chmod 400 "$SSH_PRIVATE_KEY" - ssh-add "$SSH_PRIVATE_KEY" # Create the SSH directory and give it the right permissions # - mkdir -p ~/.ssh - chmod 700 ~/.ssh # Optionally, if you will be using any Git commands, set the user name and # and email. Edit to your needs:īefore_script : # Install ssh-agent if not already installed, it is required by Docker. In the followingĮxample, a Debian based image is assumed. gitlab-ci.yml with a before_script action. The content of your private key that you created earlier. For more information, followĭo not add a passphrase to the SSH key, or the before_script willĪs Key enter the name SSH_PRIVATE_KEY and in the Value field paste In this case, you can use an SSH key pair. When your CI/CD jobs run inside Docker containers (meaning the environment isĬontained) and you want to deploy your code in a private server, you need a way $SSH_PRIVATE_KEY in the job log, though it could be exposed if you enableĬheck the visibility of your pipelines. In the following example, the ssh-add - command does not display the value of If you are accessing a private GitLab repository. ~/.ssh/authorized_keys) or add it as a deploy key Copy the public key to the servers you want to have access to (usually in.Add the private key as a file type CI/CD variable to.Create a new SSH key pair locally with ssh-keygen. ![]() gitlab-ci.yml, and it’s a solution that works The most widely supported method is to inject an SSH key into your buildĮnvironment by extending your. If anything of the above rings a bell, then you most likely need an SSH key.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |