简体   繁体   中英

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?

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)

如果您需要将yr文件复制到外部服务器,则可以使用“ scp”( http://www.tecmint.com/scp-commands-examples/ )或使用一些jenkins插件(例如,已经告诉过https:// wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin

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