3

My server is a linux Reseller plan on a2hosting with whm and cpanel.

My project is PHP Laravel.

The project builds and then using Copy Files Over SSH task I am able to copy the files to my server.

The problem is when I try to add SSH tasks after that for composer install and npm install I get errors. It is using the same SSH connection and key as the file copying task. Things like cd and ls work.

When I use that same username and that same private key locally and run composer install it works, as well as npm install. After running composer and npm the site loads fine, but I want this to be automated so I don't have to manually run those commands.

Here is my inline script:

composer install

My error looks like this:

2019-03-11T16:34:21.4468896Z ##[section]Starting: Run Composer
2019-03-11T16:34:21.4471875Z ==============================================================================
2019-03-11T16:34:21.4472119Z Task         : SSH
2019-03-11T16:34:21.4472240Z Description  : Run shell commands or a script on a remote machine using SSH
2019-03-11T16:34:21.4472332Z Version      : 0.148.0
2019-03-11T16:34:21.4472433Z Author       : Microsoft Corporation
2019-03-11T16:34:21.4472519Z Help         : [More Information](http://go.microsoft.com/fwlink/?LinkId=821892)
2019-03-11T16:34:21.4472635Z ==============================================================================
2019-03-11T16:34:21.8985848Z composer install
2019-03-11T16:34:21.9008544Z Trying to establish an SSH connection to ***@mydomain.com:7822
2019-03-11T16:34:21.9181145Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9181767Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9182133Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9182449Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9183364Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9183731Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9184084Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9184417Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9184742Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9185068Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9185405Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9185751Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:21.9186053Z (node:1296) Warning: Use Cipheriv for counter mode of aes-256-ctr
2019-03-11T16:34:22.2806417Z Successfully connected.
2019-03-11T16:34:23.0424509Z tr -d '\015' <"./sshscript_1552322" > "./sshscript_1552322._unix"
2019-03-11T16:34:23.1378047Z chmod +x "./sshscript_1552322._unix"
2019-03-11T16:34:23.2240403Z "./sshscript_1552322._unix"
2019-03-11T16:34:23.3118392Z 
2019-03-11T16:34:23.3171367Z ##[error]./sshscript_1552322._unix: line 3: composer: command not found
2019-03-11T16:34:23.3180458Z 
2019-03-11T16:34:23.3181101Z ##[error]Command failed with errors on remote machine.
2019-03-11T16:34:23.4532093Z ##[section]Finishing: Run Composer
Tyler
  • 3,713
  • 6
  • 37
  • 63
  • 2
    @jww This site is for questions about programming and **tools used by programmers**. Continuous integration / delivery questions are absolutely on-topic. – Daniel Mann Mar 12 '19 at 01:05
  • You missed the other part: *"and is ... a practical, answerable problem that is unique to software development"*. SSH is not unique to software development. Otherwise the kitchen and coffee machine would be on-topic. Maybe you should take some time to show `sshscript_1552322._unix`. Also see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – jww Mar 12 '19 at 01:10
  • This is continuous deployment for Azure Devops. They link to stack overflow for getting help with their integrations so I came here for help. If you don't understand Azure Devops then you may not be able to help. That script code is produced behind the scenes by their system, not me. I do not have access to it. I went through each step of what I did in Azure Devops. I explained the tasks that I added that worked and didn't work and explained what commands were in them. – Tyler Mar 12 '19 at 04:28

1 Answers1

3

As you can execute the commands when you login manually through SSH but you cannot execute the same commands through Azure scripts. This could mean that your pipeline script cannot load ~/.bashrc or the expected $PATH value in order to be able to find composer command. You need to ensure that your pipeline script contains the correct $PATH value by running echo $PATH manually and through pipeline script and then compare the value or you can try to put the full path of the composer binary, you can get it through manually by executing which composer , the same goes for npm.

Update: As you mentioned that you have a problem with $PATH , you can defined it manually inside the bash script that you are using like this:

export PATH=/my/missing/path:$PATH
Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61
  • You are correct, and the pipeline does not contain the same $PATH value, any idea how to fix that? They are both using the same login/ssh key – Tyler Jul 04 '19 at 03:53
  • "You need to ensure that your pipeline script contains the correct $PATH value by running echo $PATH manually" + "you can try to put the full path of the composer binary". These two sentences were the solution in my case. In my bash script I just had to replace "composer install" or "php composer install" with "/opt/cpanel/composer/bin/composer install". – pedrozopayares Oct 28 '21 at 22:28