0

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?

2
  • There are some plugins, like Publish Over SSH, that can help you Commented Apr 14, 2015 at 13:09
  • @Victor As I use gitlab, what should I enter 'source files','remove prefix'? I mean: wiki.jenkins-ci.org/download/attachments/53608875/… BTW, in 'Build Triggers' , iam using this option too: Build when a change is pushed to GitLab. GitLab CI Service URL Commented Apr 14, 2015 at 13:31

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

Bro, could U please look into here: stackoverflow.com/questions/29644940/…
@user3815806 The guy who answered that gave the correct answer. I commented there with another alternative to consider as well.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.