0

I am working on gradle script and I have one plugin which automatically download the zip,jar and war file from artifactory after that I need to do ssh to the remote server and move that zip file to particaular location.

I am trying to do in the below way but getting error

// ------ Tell the script to get dependencies from artifactory ------
buildscript {
    repositories {
      maven {
        url "http://cm.thm.com:80/artifactory/repo1-cache"
        url "http://cm.thm.com:80/artifactory/libs-snapshot"
         }
    }

    // ------ Tell the script to get dependencies from artifactory ------
    dependencies {
    classpath 'org.hidetake:gradle-ssh-plugin:0.4.3'
    classpath ([ "com.tr.cm:cmgradleplugin:1.1.118" ])
  }
}

apply plugin: 'com.truven.cm.cmgradleplugin'
apply plugin: 'org.hidetake.ssh'
/**
 * Use the deploy task to download the artifact and then unzip it to a local directory
 * -DjobName specifies the job that produced the artifact
 * -DbuildNumber specifies the build Number for the artifact
 */

 remotes {
  webServer {
    host = '10.2.12.912'
    user = 'cc'
   password = 'tr'
   // identity = file('id_rsa')
  }
}

task deployment(type: SshTask, dependsOn: deploy){
  ssh.run {
    session(remotes.webServer) {
      put(analytics-engine-AnalyticsLib-4.0.0.78.zip, "/applications/analyticsengine")
     execute 'unzip analytics-engine-AnalyticsLib-4.0.0.78.zip'
    }
  }
}

Below is the error

build file '/applications/jenkins/workspace/DeployArtifactToDev/environments/build.gradle': 43: unexpected token: 0.78 @ line 43, column 45.
     analytics-engine-AnalyticsLib-4.0.0.78.zip, 
                                   ^

  1 error

Can someone tell me my ssh code is fine or do i need to change any thing?

unknown
  • 1,815
  • 3
  • 26
  • 51

2 Answers2

1

am able to write the code for ssh

// ------ Tell the script to get dependencies from artifactory ------
buildscript {
    repositories {
      maven {
        url "http://c.t.th.com:8/artifactory/repo1-cache"
        url "http://c.t.t.com:8/artifactory/libs-snapshot"
         }
    }

    // ------ Tell the script to get dependencies from artifactory ------
    dependencies {
    classpath 'org.hidetake:gradle-ssh-plugin:1.1.1'
    classpath ([ "cm.t.cm:cmgrad:1.1.118" ])
  }
}

plugins {
    id 'war'
    id 'org.hidetake.ssh' version '1.1.1'
}

apply plugin: 'com.truven.cm.cmgradleplugin'
/**
 * Use the deploy task to download the artifact and then unzip it to a local directory
 * -DjobName specifies the job that produced the artifact
 * -DbuildNumber specifies the build Number for the artifact
 */

remotes {
    localhost {
        host = '1.2.12.1'
        user = "$deploy_username"
        password = "$deploy_dev_password"
    }
}
task deploymenttohost(dependsOn: deploy) << {
    ssh.run {
        session(remotes.localhost) {
            execute 'mkdir /applications/analyticsengine/temp'
            put from: 'build/artifacts/*.zip', into: '/applications/analyticsengine/temp'
            put from: 'deploymentfiles/*.sh', into: '/applications/analyticsengine/temp'
            execute 'unzip -d /applications/analyticsengine/temp/ /applications/analyticsengine/temp/*.zip'
            execute 'dos2unix /applications/analyticsengine/temp/analyticsEngine.sh'
            execute 'sh /applications/analyticsengine/temp/analyticsEngine.sh'
            execute 'pwd'
            execute 'rm -fr /applications/analyticsengine/temp'
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

and it is working fine

unknown
  • 1,815
  • 3
  • 26
  • 51
0

You are trying to reference an object with the name analytics-engine-AnalyticsLib-4.0.0.78.zip. That doesn't exist. What you want here is the path to your artifact as String. You are missing the quotes:

put('analytics-engine-AnalyticsLib-4.0.0.78.zip', "/applications/analyticsengine")

It's not great to use a hard-coded String because it contains the project version and the path might be incorrect depending from what directory you execute the build. It's much better if you'd reference the path of the archive you are trying to upload via the exposed property archivePath. In practice that would work as yourZipTask.archivePath.canonicalPath. yourZipTask is the instance of the ZIP task that produces analytics-engine-AnalyticsLib-4.0.0.78.zip.

Benjamin Muschko
  • 32,442
  • 9
  • 61
  • 82
  • Can you tell me one thing how could I write a code for multiple deployment host.Right now I have only one deployment host but in future if I have multiple deployment servers for Dev environment then how could I run my script in loop for each host. – unknown May 15 '15 at 16:08
  • You'd define multiple hosts in the `remotes` closure. Then based on a provided command line option `-P`, you pick the one you want to use in `ssh.run.session` at runtime. Please refer to the Gradle documentation for more information on how to use/resolve project properties. – Benjamin Muschko May 15 '15 at 16:12