'Show remote command output in CI job results

I have CI pipeline which have stages like this. As it shows most of the stuff here is done on remote machine which is working fine.

The only issues I am unable to see the command outputs here. For e.g. scp is used with -v which if run manually on machine shows a lot of verbose information useful for debugging etc. same goes for cp -v but in job results it shows no such information.

So is there a way I can re-route the command outputs from remote machine to local (gitlab job output)

my job 1/6:
  rules:
    - changes:
      - ${LOCA_FILE_PATH}
  stage: prepare
  allow_failure: true
  script: |
    ssh ${USER}@${HOST} '([ -f "${PATH}/test_conf_1.txt" ] && cp -v "${PATH}/test_conf_1.txt" ${PATH}/test_yaml_$CI_COMMIT_TIMESTAMP.txt)'
    
my job 2/6:
  rules:
    - changes:
      - ${LOCA_FILE_PATH}
  stage: scp
  script:
    scp -v ${TF_ROOT}${LOCA_FILE_PATH} ${USER}@${HOST}:${PATH}/


Solution 1:[1]

Perhaps you can try something like this:

ssh user@host 2>&1 command | tee ssh-session.log
cat ssh-session.log

Solution 2:[2]

In the script part you can define a variable and hold there the result of your command and you can print this out.

script:
- RESULT=$(scp -v ${TF_ROOT}${LOCA_FILE_PATH} ${USER}@${HOST}:${PATH}/)
- echo $RESULT

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 frakman1
Solution 2 isori