我从春季启动就开始了我的第一个Rest API项目。我创建了一些不太高级的程序。该项目的插件可以帮助我创建新的.jar文件,该文件可以通过SSH客户端安装在我的VPS服务器上。在底部,我提供了正确安装Serwer上的.jar文件所必须采取的示意图。
如您所见,这需要很多时间。存在任何程序或可以自动编程的程序吗?我听说过詹金斯吗?您有什么建议可以节省我一些时间:D?
[非常感谢和抱歉,我的英语,我知道这还不够好,但是我已经尽力了:D西蒙妮
是的,可以使用詹金斯实现。首先将您的代码提交到git仓库。一旦您在系统上安装了jenkins。从jenkins仪表板中选择新项目。输入此商品的名称然后选择类型,您应该选择“管道”。在下一页的“定义”部分中选择“高级项目选项”,请按照以下共享的示例代码创建自己的管道脚本。
有关管道的更多信息,请访问Jenkins pipeline getting started
#!/usr/bin/env groovy
node('master'){
try {
def mvnHome
def projectDirectoryPath
def serverPath = '/app/projects/myapp/services/'
def jarName = 'myapp-0.0.1-SNAPSHOT.jar'
stage('checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/YOURGITBRANCH']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'YOURGITCREDENTIALID', url: 'YOURGITURL']]])
mvnHome = '/usr/apache-maven-3.1.1'
projectDirectoryPath = '/app/jenkins-slave/workspace/myapp_services'
}
stage('clean') {
sh "cd '${projectDirectoryPath}' && '${mvnHome}/bin/mvn' clean"
}
stage('build') {
sh "cd '${projectDirectoryPath}' && '${mvnHome}/bin/mvn' package"
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
stage('deploy') {
sshagent(['YOURAGENTID']) {
echo "the application is deploying ${jarName}"
sh "ssh -o StrictHostKeyChecking=no USER@YOURHOST ${serverPath}stop.sh"
echo "the ${jarName} is stopped"
sh "scp ${projectDirectoryPath}/target/${jarName} USER@YOURHOST:${serverPath}${jarName}"
echo "the ${jarName} is transferred successfuly"
sh "ssh -o StrictHostKeyChecking=no USER@YOURHOST sh ${serverPath}start_silent.sh"
echo "the ${jarName} is started successfuly"
}
}
}catch(e){
currentBuild.result="FAILED"
//notifyfailed()
throw e
}
}