I am currently working on creating a Jenkins job with Kubernetes and Karate to display a few test results using Cucumber reports. I am having difficulties trying to obtain environment variables passed into the deployment file through a configmap, as follows:
Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-deployment
spec:
selector:
matchLabels:
app: jenkins
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: url/customjenkinsimage:tag
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: jenkins-configmap
ConfigMap:
kind: ConfigMap
apiVersion: v1
metadata:
name: jenkins-configmap
data:
# pass data as environment variables
URL_TO_TEST: "http://www.examplewebsite.com"
I looked this up and saw that some people mentioned using karate.properties['VAR_NAME'] inside the karate-config.js file and passing that through the config, but this resulted in my jenkins output telling me that the 'url' part in Given url host1
doesn't exist. I've tried process.env as well (which of course doesn't work but it was worth a shot)
I was wondering if there is any way to access this environment variable in the karate-config.js (or even if I pass a json object in the configmap) since I would need it to build a url to pass to the feature for testing.
my karate-config.js:
function fn() {
var config = {
host1: karate.properties['URL_TO_TEST']
};
return config;
}
All of these files get put into the /var/jenkins_home/jobs/karate_job/workspace/ folder to run using a Shell command: cd /var/jenkins_home/jobs/karate_job/workspace/ ; java -jar karate.jar test.feature
.
Any help would be appreciated, Thanks.