Add other environments to gradle deploy

Enonic version: XP 6
OS: OSX

Hi.

I’m not that familiar with gradle so my wish might be very easy to fix, but are there a way to expand the gradle deploy command to deploy to external server?

I would like to just do ‘gradle deploy production’ or such to deploy to a configured server. Is this possible or even recommended?

At work we would use an artifact repository and fetch it from the after release with jenkins or like that and deploy but for very simple sites that is something that I dont want to bother with.

It would be awesome to just be able to configure a to deploy to and do it via gradle.

How do you deploy? Manual copy to the server?

Hi

We simply do “Gradle publish”, so this is possible. I will ask our Gradle expert to post more details on how this is done, and what is required.

It’s possible to do anything in Gradle :slight_smile: What you can do in your case is to configure a SSH connection via Gradle and then just SCP (secure copy) into the deploy folder. I have not done this myself, but I think it’s a relatively small job using existing Gradle plugins (for example: https://github.com/int128/gradle-ssh-plugin).

With the above plugin I would do something like this (keep in mind that I have not tried it and it’s just written inside this editor without any actually tests):

remotes {
  prod {
     host = ...
     user = ...
     password = ...
  }
} 

task deployToProd << {
  ssh.run {
     session(remotes.prod) {
       put from: jar.archivePath, into: '/deploy/dir/on/server'
     }
  }
}

deployToProd.dependsOn = build

After that you can just run the following command:

./gradlew deployToProd

Here’s some documentation references:

Hope that helps.

2 Likes

Hey,

I used this setup to get ssh deployment to work

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url 'http://repo.enonic.com/public'
        }
    }

    dependencies {
        classpath "com.enonic.xp:gradle-plugin:${xpVersion}"
        classpath 'org.hidetake:gradle-ssh-plugin:1.1.3'
    }
}

apply plugin: 'org.hidetake.ssh'
apply plugin: 'com.enonic.xp.app'
apply plugin: 'java'
apply plugin: 'idea'

app {
    name = project.appName
    displayName = project.displayName
    vendorName = 'dataDigg.no'
    vendorUrl = 'http://www.datadigg.no'
}

dependencies {
    include "com.enonic.xp:lib-content:${xpVersion}"
    include "com.enonic.xp:lib-portal:${xpVersion}"
    include "com.enonic.xp:lib-thymeleaf:${xpVersion}"
    include "com.enonic.lib:util:1.0.0"
    include "com.enonic.lib:menu:1.0.0"
}

remotes {
    prod {
        host = 'admin.datadigg.no'
        user = '<YOUR USER>'
        agent = true
        identity = file("${System.getProperty('user.home')}/.ssh/id_rsa")
        //knownHosts = allowAnyHosts
    }
}

task deployToProd(dependsOn: build) << {
    ssh.run {

        session(remotes.prod) {
            put from: jar.archivePath, into: '/opt/datadigg-enonic-xp/home/deploy'
        }
    }
}


repositories {
    mavenLocal()
    jcenter()
    maven {
        url 'http://repo.enonic.com/public'
    }
}
3 Likes