user3815806
user3815806

Reputation: 243

jenkins script code issue in execute shell

Iam using jenkins, i am trying to deploy my code into prod server using gitlab. So i created a new project, selected git project and branch, chosen Poll SCM.

Now in execute shell, i am using script code as below:

ssh user@prod-server // in log, user got logged in
cd /myfolder   // in log showing 'myfolder' not found

Seems like jenkins checking 'myfolder' folder inside local server rather than in prod server and so saying as 'not found'.

So, how do I fix this? Why jenkins not checking 'myfolder' in producion server?

Upvotes: 0

Views: 501

Answers (2)

Slav
Slav

Reputation: 27485

Your issue that you don't have an interactive session, after the ssh command is executed (unlike what you'd have if you were sitting at the terminal)

If it's just one command, you could pass it to ssh, like so:
ssh user@prod-server 'cd /myfolder'

You could even chain several commands together:
ssh user@prod-server 'cd /myfolder && cat myfile'

Use the following command separators:
- ; to execute next command always.
- && to execute next command only if previous was success.
- || to execute next command only if previous was failed.

But once you get too many commands, it's better to put them in a shell script, and execute that shell script:
ssh user@prod-server 'bash -s' < /path/to/local_script.sh
(Note, in above example, the local_script.sh does not need to be copied to server)

Upvotes: 1

Stan
Stan

Reputation: 3461

If you need to copy yr files to external server, you can use "scp" (http://www.tecmint.com/scp-commands-examples/) or use some jenkins plugins (e.g as was already told https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin)

Upvotes: 0

Related Questions