Skip to content

Commit

Permalink
basic feature branches support
Browse files Browse the repository at this point in the history
  • Loading branch information
jk1 committed Feb 23, 2015
1 parent e4cc56e commit 64eeb7e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ configurations.all {
}
```

Changing dependencies may be also resolved against particular [feature branches](https://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches):

```groovy
dependencies {
compile tc(buildTypeId: 'bt345', version: 'lastSuccessful', artifactPath: 'testng-6.8.8.jar', branch: 'master')
}
```

Default branch will be used if branch value is not specified explicitly.

###Pinning the build

By default, TeamCity does not store artifacts indefinitely, deleting them after some time. To avoid dependency loss one may choose to [pin the build](https://confluence.jetbrains.com/display/TCD8/Pinned+Build) as follows:
Expand All @@ -70,7 +80,7 @@ repositories{
teamcityServer{
url = 'http://teamcity.jetbrains.com'
pin {
// pinning usually requires authnetication
// pinning usually requires authentication
username = "name"
password = "secret"
stopBuildOnFail = true // not mandatory, default to 'false'
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'maven'

group = 'com.github.jk1'
description = 'TeamCity dependencies plugin resolves project dependencies via local TeamCity server'
version = '0.5'
version = '0.6'

repositories {
mavenCentral()
Expand Down
4 changes: 3 additions & 1 deletion consumer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = '1.0'

repositories {
teamcityServer {
url = 'http://teamcity.jetbrains.com'
url = 'https://teamcity.jetbrains.com'
}
}

Expand All @@ -27,6 +27,8 @@ dependencies {
compile tc('bt131:lastPinned:javadocs/index.html')
compile tc('bt337:lastSuccessful:odata4j.zip')
compile tc('bt132:sameChainOrLastFinished:index.html')
// with feature branches supported
compile tc(buildTypeId: 'bt345', version: 'lastSuccessful', artifactPath: 'testng-6.8.8.jar', branch: 'master')
}

defaultTasks 'listdeps'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.gradle.api.Project
class ArtifactVersion {

def versionPlaceholders = ['lastFinished':'',
'lastPinned': 'pinned:true',
'lastPinned': ',pinned:true',
'lastSuccessful':',status:SUCCESS',
'sameChainOrLastFinished':'']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@ class BranchScopedArtifactVersion extends ArtifactVersion {

@Override
def resolve(Project project, String btid) {
String request = url(project.teamcityServer.url, btid)
String response = "<no response recorded>"
try {
HttpURLConnection connection = url(project.teamcityServer.url, btid).toURL().openConnection()
HttpURLConnection connection = request.toURL().openConnection()
response = connection.inputStream.withReader { Reader reader -> reader.text }
if (connection.getResponseCode() == 200) {
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
project.logger.info("$version has been resolved as $response in $branch")
version = response
changing = false
} else {
String message = "Unable to resolve $version in $branch. Server response: \n $response"
throw new GradleException(message, e)
String message = "Unable to resolve $version in $branch.\nRequest: GET $request \nServer response: \n $response"
throw new GradleException(message)
}
} catch (Exception e) {
String message = "Unable to resolve $version in $branch. Server response: \n $response"
String message = "Unable to resolve $version in $branch.\nRequest: GET $request \nServer response: \n $response"
throw new GradleException(message, e)
}
}

private def url(String server, String btid) {
def query = "buildType:$btid,branch:$branch,${versionPlaceholders[version]}/number"
def query = "buildType:$btid,branch:$branch${versionPlaceholders[version]}/number"
return "${server}/guestAuth/app/rest/builds/$query"
}
}

0 comments on commit 64eeb7e

Please sign in to comment.