hi are there any good tutorials on how to apply co...
# pact-jvm
t
hi are there any good tutorials on how to apply consumer versioning (branches) when publishing with pact (both/either via gradle ideally or pact cli) ?
n
This is how I publish my consumer pacts:
pact-broker publish build/pacts --consumer-app-version=$(git rev-parse HEAD) --branch=$(git rev-parse --abbrev-ref HEAD)
If you want to use the gradle plugin something like this…. (Think this was in one of the pact JVM tutorials
Copy code
def getGitHash = { ->
	def stdout = new ByteArrayOutputStream()
	exec {
		commandLine 'git', 'rev-parse', 'HEAD'
		standardOutput = stdout
	}
	return stdout.toString().trim()
}

def getGitBranch = { ->
	def stdout = new ByteArrayOutputStream()
	exec {
		commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
		standardOutput = stdout
	}
	return stdout.toString().trim()
}

static def getOrDefault(env, defaultVal) {
	def val = System.getenv(env)
	if (val == null || val.isEmpty()) {
		val = defaultVal
	}
	return val
}

pact {
	broker {
		pactBrokerUrl = getOrDefault("PACT_BROKER_BASE_URL", null)
		pactBrokerToken = getOrDefault("PACT_BROKER_TOKEN", null)
	}

	publish {
		consumerVersion = getGitHash()
		consumerBranch = getGitBranch()
		//tags = [getGitBranch()]
	}

}
t
thank you, thats actually what ive ended up doing too just this morning, glad my understanding was on the right track
👍 1