1. import java.text.SimpleDateFormat
    2. def getRemoteServer(ip){
    3. def remote = [:]
    4. remote.name = 'root'
    5. remote.host = ip
    6. remote.user = 'root'
    7. remote.password = 'xxxxxx'
    8. remote.allowAnyHosts = true
    9. // withCredentials([usernamePassword(credentialsId: 'wukang', passwordVariable: 'password', usernameVariable: 'userName')]) {
    10. // remote.user = "${userName}"
    11. // remote.password = "${password}"
    12. // }
    13. return remote
    14. }
    15. def time = '222222'
    16. // parameters {
    17. // booleanParam(name: 'isPublishVersion', defaultValue: false, description: '默认不发布')
    18. // choice(choices: ['origin/release-bugfix', 'origin/release', 'origin/master'], description: '构建分支选择,默认origin/release-bugfix' , name: 'GIT_LOCAL_BRANCH')
    19. // }
    20. pipeline {
    21. agent any
    22. parameters {
    23. gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH'
    24. }
    25. stages {
    26. // stage('连接跳板机') {
    27. // steps {
    28. // script{
    29. // remote = getRemoteServer("192.168.0.9")
    30. // sshCommand remote: remote, command: "ls -lrt"
    31. // sshCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
    32. // }
    33. // }
    34. // }
    35. stage('拉取代码') {
    36. steps {
    37. git branch: "${params.BRANCH}", credentialsId: 'c2232f1a-c44c-4ac8-956d-92b40e4343d3', url: 'http://192.168.0.212/npay/code/mlang.git'
    38. }
    39. }
    40. stage('编译构建') {
    41. steps {
    42. sh 'mvn clean package'
    43. }
    44. }
    45. stage('上传ftp') {
    46. steps {
    47. script{
    48. def dateFormat = new SimpleDateFormat("yyyyMMddHHmm")
    49. def date = new Date()
    50. time = dateFormat.format(date)
    51. }
    52. sh """
    53. lftp <<END
    54. open 47.243.85.49 -p 21
    55. user deploy fccFbBGfvtjpYFGm
    56. cd data_center
    57. mkdir ${time}
    58. cd ${time}
    59. mkdir code
    60. mkdir conf
    61. cd code
    62. mput target/*.jar
    63. ls
    64. END
    65. echo "上传在ftp目录:/data_center/${time}/code/"
    66. """
    67. }
    68. }
    69. stage('代码部署') {
    70. steps {
    71. script{
    72. remote = getRemoteServer("192.168.0.9")
    73. sshCommand remote: remote, command: "cd /data/files;wget -nH -r ftp://deploy:xxxxx@47.243.85.49/data_center/${time}"
    74. }
    75. echo '代码部署'
    76. echo "/data_center/${time}/code/"
    77. // sh 'ansible all -m ping'
    78. }
    79. }
    80. stage('配置分发') {
    81. steps {
    82. echo '配置分发'
    83. }
    84. }
    85. stage('重启服务') {
    86. steps {
    87. echo '重启服务'
    88. }
    89. }
    90. }
    91. }