Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / PowerShell
Tip/Trick

Automate CodePlex Releasing with PowerShell and Web Services

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
6 Nov 2013CPOL 7.2K   2  
Creating new release and uploading release files in one click

Introduction

Searching for a way to automate ConEmu's release creation on CodePlex.com, I found information about CodePlexAPI. I have not used WebServices before and fail to find usage examples.

Background

Well, Googling for any CodePlex uploaders, I've found CodeplexReleaseTool. Open source, C#, required some dependencies... But not so clear as I've searched for.

Using the Code

Fortunately, PowerShell can call WebServices easily. Just create an object and use $codeplex methods.

$codeplex = New-WebServiceProxy 
-Uri https://www.codeplex.com/Services/ReleaseService.asmx -Namespace Codeplex 

The following script Codeplex.ps1 creates new release containing three files. Most of the parameters are passed with script arguments.

param([String]$buildno="131105",[String]$folder="",
[String]$type="Alpha",[String]$txtfile="",[String]$user,[String]$password)

$project = "conemu"
$showToPublic = 1
$isDefaultRelease = 1

#folder if not specified - use current, need trailing backslash
if ($folder -eq "") { $folder = (Get-Location).Path }
if ($folder.Substring($folder.Length-1) -ne "\") { $folder += "\" }

#make release date in format "YYYY-MM-DD"
#our $buildno has format "YYMMDD", just split it
$reldate = ("20" + $buildno.Substring(0,2) + "-" + 
$buildno.Substring(2,2) + "-" + $buildno.Substring(4,2))

#now, create an array with release file names
$files = ("","","")
$files[0] = ($folder + "ConEmuPack." + $buildno + ".7z")
$files[1] = ($folder + "ConEmuSetup." + $buildno + ".exe")
$files[2] = ($folder + "ConEmu_" + $buildno + "_English_online.paf.exe")
#file[0] will be "Recommended" release
$defFile = (Get-Item $files[0]).Name

#create release name and status
if ($type -eq "Alpha") {
  $relname = ("ConEmu " + $buildno + " [Alpha]")
  $status = "Alpha"
} elseif ($type -eq "Preview") {
  $relname = ("ConEmu " + $buildno + " [Preview]")
  $status = "Beta"
} else {
  $relname = ("ConEmu " + $buildno + " [Stable]")
  $status = "Stable"
}

#read release description from text file
if ($txtfile -ne "") {
  $reldescr = [System.IO.File]::ReadAllText($txtfile)
} else {
  $reldescr = ""
}

### Done with parameters initialization ###
#create service
$codeplex = New-WebServiceProxy 
-Uri https://www.codeplex.com/Services/ReleaseService.asmx -Namespace Codeplex

#create release
$codeplex.CreateARelease($project,$relname,$reldescr,
$reldate,$status,$showToPublic,$isDefaultRelease,$user,$password)

#read files into byte array
$i = 0
$ff = $files
$files | ForEach {
  $fItem = Get-Item $_
  $ff[$i] = New-Object Codeplex.ReleaseFile
  $ff[$i].FileData = [System.IO.File]::ReadAllBytes($_)
  $ff[$i].FileName = $fItem.Name
  $ff[$i].FileType = "RuntimeBinary"
  $i += 1
}
#upload release files
$codeplex.UploadTheReleaseFiles($project,$relname,$ff,$defFile,$user,$password)

Near this script, I've created simple text file CodePlex.wiki with release description.

At last, batch file ConEmuUploadPL.cmd to simplify calling ps1 script.

@echo off
if "%~2"=="" (
echo Usage: %~nx0 ^<BuildNo^> ^<Alpha^|Preview^|Stable^>
goto :EOF
)
powershell "%~dp0Codeplex.ps1" -user UserName -password YourPassword 
-buildno %1 -folder "C:\Projects\ConEmu" -type "%~2" 
-txtfile "%~dp0CodePlex.wiki" 

History

  • 1.0 Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Leased line customers
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --