简体   繁体   English

jenkins脚本代码在执行shell中的问题

[英]jenkins script code issue in execute shell

Iam using jenkins, i am trying to deploy my code into prod server using gitlab. 我正在使用jenkins,我正在尝试使用gitlab将代码部署到产品服务器中。 So i created a new project, selected git project and branch, chosen Poll SCM. 所以我创建了一个新项目,选择了git项目和分支,选择了Poll SCM。

Now in execute shell , i am using script code as below: 现在在execute shell中 ,我正在使用如下脚本代码:

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'. 好像詹金斯在本地服务器而不是产品服务器中检查“ myfolder”文件夹,所以说是“未找到”。

So, how do I fix this? 那么,我该如何解决呢? Why jenkins not checking 'myfolder' in producion server? 为什么詹金斯不检查生产服务器中的“ myfolder”?

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) 在执行ssh命令后,您没有交互式会话的问题(与坐在终端上时的情况不同)

If it's just one command, you could pass it to ssh , like so: 如果只是一个命令,则可以将其传递给ssh ,如下所示:
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) (注意,在上面的示例中,不需要将local_script.sh复制到服务器)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM