Search code examples
sshgitlabgitlab-ci-runner

gitlab launch shell pipelines with specific user


gitlab_version: 14.1.1-ee

I copied ssh-id to targuet host with the user "user".

When I create a pipeline with "shell" runner I have a problems to comunicate to other hosts by ssh.

I created a simple task with "id" command, this return "root".

How to launch gitlab pipelines with "user" user.

Thank's.


Solution

  • I found how to connect to linux target host with "other user" than "runner user".

    Procedure:

    1. Install sshpass on gitlab server host.
    2. On Project_name/settings/"CI/CD"/Variable, create a pass_var with password string on key value.
    3. On pipeline/editor in script line of .gitlab-ci.yml:
    script:
    - sshpass -p $pass_var ssh user@host_ip "hostname"