Skip to content

Instantly share code, notes, and snippets.

@akashdktyagi
Created January 23, 2023 11:53
Show Gist options
  • Save akashdktyagi/eddc87cbfb2de2bbf8448c032a285509 to your computer and use it in GitHub Desktop.
Save akashdktyagi/eddc87cbfb2de2bbf8448c032a285509 to your computer and use it in GitHub Desktop.
Run Side Card Container With in a Jenkins Pipeline
def withDockerNetwork(Closure inner) {
try {
networkId = UUID.randomUUID().toString()
sh "docker network create ${networkId}"
inner.call(networkId)
} finally {
sh "docker network rm ${networkId}"
}
}
pipeline {
agent none
environment {
}
stages {
stage("test") {
agent any
steps {
script {
def selenium = docker.image("selenium/standalone-chrome:4.7.2-20221219")//, "grid-chrome")
def app = docker.image("temp/devcloud-build-java:11")
withDockerNetwork{ n ->
selenium.withRun("--network ${n} --name selenium -p 4444:4444") { c ->
app.inside("""
--network ${n} -e 'gridUrl=http://selenium:4444'
""") {
sh 'mkdir -p ~/.m2/ && cp ${MAVEN_SETTINGS_PATH} ~/.m2/settings.xml'
sh 'mvn install'
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment