[英]Create a Jenkins job to deploy a file on a server
I am working on a Jenkins job that will download a specific file from a GIT repo and then deploy it on a server to a specified location.我正在处理 Jenkins 作业,该作业将从 GIT 存储库下载特定文件,然后将其部署到服务器上的指定位置。 Jenkins job will ask below variables from the user:
Jenkins 作业将向用户询问以下变量:
Here's what I have done so far:这是我到目前为止所做的:
Here's what the code looks like so far:到目前为止,代码如下所示:
git checkout $commit $filename
scp $filename username@$servername:/path/to/deploy/
The challenge is how to feed the variables to the shell script.挑战在于如何将变量提供给 shell 脚本。 Is it even possible to do it this way?
甚至可以这样做吗? Any help would be appreciated.
任何帮助,将不胜感激。
Below solution worked.以下解决方案有效。
Added the GIT repo to the Jenkins freestyle job将 GIT 回购添加到 Jenkins 自由式作业
After checking the option, 'this project is parameterized', I added 3 variables as shown.选中选项“此项目已参数化”后,我添加了 3 个变量,如图所示。
Then modified the shell script as below然后修改shell脚本如下
#!/bin/bash
pwd
ssh ansible@$server_name "cp "$File_path"/"$file_name" "$File_path"/"$file_name"_"$(date +"%Y-%m-%d")";"
scp $file_name ansible@$server_name:$File_path
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.