'Docker Image to run sql query
I need to create dockerfile to create container to be able to run queries on my db from jenkins pipeline(do not wanna use jenkins plugin or db driver on slaves)
pipeline {
agent {
dockerfile { 'my_docker_file' }
}
stages {
stage('Test') {
steps {
sh'''#!/bin/bash
USER='username'
PASS='password'
PORT=3160
HOST='hostname'
DBASE='mysqlDbName'
Query='SELECT * FROM table WHERE some=other LIMIT 10'
mysql -u$USER -p$PASS -P$PORT -h$HOST -D$DBASE <<EOF
$Query
EOF
'''
}
}
}
}
Do not bother too much about the shell script, it is just for illustration
So how should this dockerfile looks like to achieved this? I tried(cannot use images outside company):
FROM our_nexus_url/ubuntu
RUN apt-get update -qq && apt-get install -y mysql-client
... or second option is to run the query inside the container and only return result to jenkins
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
