Custom Deployment Script to post AEM package

Hi,

I am trying to use Octopus Deploy to deploy a package to Adobe Experience Manager (AEM). I’m assuming this would be possible using a Deployment Script as all we would need to do is post the package using a web api call, and then call the deploy method on the API.

However I’m struggling to figure out how to do this. I’ve setup a tentacle on the AEM server and the package is being copied over, and I cannot figure out what variable to use or how to set the deployment script to run the web api post command. My c# deployment script code looks like this (this works in a console app):

var packageName = Octopus.Parameters[""]; //WHAT IS THIS SUPPOSED TO BE???
System.Net.Http.HttpContent content = new System.Net.Http.ByteArrayContent(System.IO.File.ReadAllBytes(packageName));
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip");

using (var form = new System.Net.Http.MultipartFormDataContent())
{
    form.Add(content, "package", "packagename.zip");

    using (var client = new System.Net.Http.HttpClient())
    {
        var byteArray = System.Text.Encoding.ASCII.GetBytes("username:password");
        var header = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
        client.DefaultRequestHeaders.Authorization = header;

        var response = client.PostAsync("http://server:port/crx/packmgr/service/.json/?cmd=upload", form).Result;
        System.Console.WriteLine(response.Content.ReadAsStringAsync().Result);
    }
}

Can you help? Is what I’m trying possible?

Hi,

Thanks for reaching out! I’m not sure I understood this part: Is the script being executed at all?

  • If its not being executed: Could you show me where are you putting this script so it gets executed after the package gets deployed to the server? Ideally you should be using it in a Post deploy script in the package step

  • If its being executed: Would you mind adding a few Console.WriteLine in a couple of parts of the script so we can stablish up to which part it is being executed?

  • In any case: Please send me a full deployment log so we can check what’s going on during the deployment: http://docs.octopusdeploy.com/display/OD/Get+the+raw+output+from+a+task

Thanks!
Dalmiro

Hi,

I did get this to work, but for anybody reading this and to clarify, I’m using Octopus Deploy version 3.13.1 and what I did:

  • Create a “Deploy a Package” step
  • In “Configure Features” un-check everything and only select “Custom deployment scripts”
  • You should see three places to add scripts, “Pre-deployment script”, “Deployment script” and a “Post-deployment script”. In the “Deployment Script” add the following C# script:
var packageName = Octopus.Parameters["Octopus.Tentacle.CurrentDeployment.PackageFilePath"];

System.Net.Http.HttpContent content = new System.Net.Http.ByteArrayContent(System.IO.File.ReadAllBytes(packageName));
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip");

using (var form = new System.Net.Http.MultipartFormDataContent())
{
	form.Add(content, "package", "package.zip");

	using (var client = new System.Net.Http.HttpClient())
	{
		var byteArray = System.Text.Encoding.ASCII.GetBytes("username:password");
		var header = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
		client.DefaultRequestHeaders.Authorization = header;

		var response = client.PostAsync("http://server:port/crx/packmgr/service/.json/packagepath/packagename.zip?cmd=upload", form).Result;
		var result = response.Content.ReadAsStringAsync().Result;

        if (result.Contains("false"))
            throw new Exception(result);

		System.Console.WriteLine(result);
	}
}

This is working, the issue that I had was trying to figure out what to set the “packageName” variable to, but I eventually figured that out.

Thanks!

Glad to hear you got it working in the end :slight_smile:

Cheers!