1

I'm trying to use Karate Netty jar in a gitlab-ci pipeline. I'm pulling in an image that contains the jar as a step in the pipeline. I am able to execute tests just fine for unsecured services. Like so:

karate-test:
    stage: acceptance-test
    image:
        name: registry.gitlab.opr.business.org/karate-universe:0.0.3
        entrypoint: [ "" ]
    script:
        - java -jar /karate.jar -e dev src/test/karate/acceptance-test.feature -o /target/karate
    environment:
        name: Test
    artifacts:
        paths:
            - /target/karate

Now I'm trying to pass credentials into a karate feature for a secured service but cannot find the capabilities from the jar interface.

I've tried passing the credentials like so:

    - java -jar /karate.jar -e dev src/test/karate/acceptance-test.feature -o /target/karate -Duser.password ${REQUEST_PASSWORD} -Duser.id ${REQUEST_USER}

REQUEST_PASSWORD and REQUEST_USER are gitlab variables that are available to me in gitlab-ci.

When I run the pipeline, I get:

Unmatched arguments [-Duser.password, -Duser.id]

Does Karate Netty have the capabilities of being able to pass variables for karate-config use like regular Karate does? I cannot keep secrets in the karate-config file itself.

darktrek
  • 132
  • 1
  • 9

1 Answers1

1

Make sure the -Dfoo=bar part comes before the -jar option, because everything after that is passed to Karate, and not the JVM.

java -Dfoo=bar -Dbaz=ban -jar /karate.jar

Note that you can also get environment variables easily:

java.lang.System.getenv('PATH')

Normally people pass values as -D JVM options. If you have some advanced needs for the standalone JAR - see this: https://stackoverflow.com/a/56458094/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I was already using the -D variables, but this got me on the right track! I was putting them at the end instead of before the -jar switch. – darktrek Jul 30 '19 at 16:20
  • 1
    I forget the javascript is running in a JVM... Counterintuitive for me to grab environment variables using javascript, but I'm glad its so simple! – darktrek Jul 30 '19 at 16:23
  • 1
    I actually used karate.properties['userId'] instead of java.lang.System.getenv. Couldn't seem to get that to work. – darktrek Jul 30 '19 at 21:10