Publish Pacts
Code snippets to connect to your broker
Consumer
Pact JS (Node JS)
- Pact-JS documentation for all the pact publication options.
const { Publisher } = require("@pact-foundation/pact")
const opts = {
pactBroker: 'https://<YOUR_BROKER>.pactflow.io',
pactBrokerToken: '<TOKEN>',
consumerVersion: process.env.GIT_COMMIT
pactFilesOrDirs: ['./pacts'],
};
new Publisher(opts).publishPacts()
Java / JUnit 5
- Pact-JVM documentation for all the pact publication options.
pact {
publish {
providerVersion = { '<GIT_COMMIT>' } //yes, this field name is correct :(
pactBrokerUrl = 'https://<YOUR_BROKER>.pactflow.io/'
pactBrokerToken = '<TOKEN>'
}
}
Java / JUnit 4
pact {
publish {
providerVersion = { '<GIT_COMMIT>' } //yes, this field name is correct :(
pactBrokerUrl = 'https://<YOUR_BROKER>.pactflow.io/'
pactBrokerToken = '<TOKEN>'
}
}
Java / Gradle
pact {
publish {
providerVersion = { '<GIT_COMMIT>' } //yes, this field name is correct :(
pactBrokerUrl = 'https://<YOUR_BROKER>.pactflow.io/'
pactBrokerToken = '<TOKEN>'
}
}
Golang
p := dsl.Publisher{}
err := p.Publish(types.PublishRequest{
PactURLs: []string{"/path/to/pact/file"},
PactBroker: "https://<YOUR_BROKER>.pactflow.io",
ConsumerVersion: "<GIT_COMMIT>",
BrokerToken: "<TOKEN>",
})
Ruby
- Pact Ruby documentation for all the pact publishing options.
Rakefile
require 'pact_broker/client/tasks'
PactBroker::Client::PublicationTask.new do | task |
task.consumer_version = ENV['GIT_COMMIT']
task.pact_broker_base_url = "https://<YOUR_BROKER>.pactflow.io"
task.pact_broker_token = "<TOKEN>"
end
.NET
- PactNet documentation for all the pact publishing options.
Pact Publisher options
var pactPublisher = new PactPublisher("http://<YOUR_BROKER>.pactflow.io",
new PactUriOptions("<TOKEN>"));
pactPublisher.PublishToBroker("/pact/to/pacts/dir",
Environment.GetEnvironmentVariable("GIT_COMMIT"));
Docker
- Pact CLI Docker documentation for all the pact publishing options.
docker run --rm \
-v ${PWD}:${PWD} \
-e PACT_BROKER_BASE_URL="https://<YOUR_BROKER>.pactflow.io" \
-e PACT_BROKER_TOKEN="<TOKEN>" \
pactfoundation/pact-cli:latest \
publish \
${PWD}/pacts \
--consumer-app-version ${GIT_COMMIT}
Branches
Configuring the branch when publishing pacts
- Pact CLI
- Ruby
See here for full docs.
pact-broker publish ./pacts --consumer-app-version $GIT_COMMIT --branch $GIT_BRANCH
# or
pact-broker publish ./pacts --auto-detect-version-properties
See here for full docs.
# In Gemfile
gem "pact_broker-client"
# In Rakefile
require "pact_broker/client/tasks"
PactBroker::Client::PublicationTask.new do | task |
task.consumer_version = ENV["GIT_COMMIT"]
task.branch = ENV["GIT_BRANCH"]
end