简体   繁体   中英

GitLab CI/CD Pipeline - Run Linux commands interactively on GitLab Runner

I am trying to provision and configure some Azure infrastructure using terraform which will be orchestrated via a GitLab CI/CD pipeline running off a GitLab Runner hosted on an Azure Linux VM. The Azure Linux VM which has been manually provisioned, has a named Admin called azureuser .

I'd like to install and configure the GitLab Runner (including its dependencies) using a dedicated GitLab CI/CD pipeline and as a result, run all the required Linux commands interactively on the aforementioned Azure Linux VM . How can I achieve this?

I've been following the steps outlined in this GitLab documentation https://docs.gitlab.com/ee/ci/ssh_keys/ and as part of an initial dry-run, I manually installed the GitLab Runner on my Azure Linux VM using the Root account.

On the other hand, I did create the required Private and Public Keys in the home directory of the azureuser account as depicted in the screenshot below. I manually run all the checks to confirm that the GitLab Runner and Docker Executor were both up and running, as well as other dependencies.

在此处输入图像描述

Then from my .gitlab-ci.yml file, I tried to execute some very basic Linux commands - sudo yum -y update and sudo gitlab-runner status - but then received the following error message:

.gitlab-ci.yml 交互式命令

/bin/sh: eval: line 146: sudo: not found

sudo:未找到错误

  1. What could I be doing wrong when trying to run those commands interactively on my Azure Linux VM GitLab Runner?

  2. Was it okay for me to install the Runner and also generate the SSH keys with two different accounts as described above?

You'll have to append any commands you want to execute in your remote session in the command clause of the ssh command:

- ssh $SSH_USER@$VM_IPADDRESS "hostname && echo 'Welcome!!!' > welcome.txt && sudo yum -y update && sudo gitlab-runner status"

I'm not sure exactly why this happens, but it does not fully open a remote session like it would if you ran ssh locally. It will run the indicated commands and exit. So as it is currently, your two sudo commands run on the gitlab-runner host (or a container running on the runner, depending on your executor) and you get "command not found".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM