1

I am trying to run a scenario in jenkins that works locally, but it is complaining that it can't find the file. Where does jenkins create the file by default if I use the karate.write function?

Tried to read the file by using:

def opportunityID = read('file:target/OpportunityID.txt')

This works locally but when ran in jenkins it doesn't like it and complains about unable to find file.

// Code used to perform karate.write

  • def txtFileName = 'OpportunityID.txt'
  • def value = function writeOpportunityIDToFile(value,textFileName) { var time = java.lang.System.currentTimeMillis(); karate.write(value, textFileName); karate.log('saved opportunity id to:', textFileName); }
  • call writeOpportunityIDToFile(opportunityID,txtFileName);

Error message when running in jenkins:

"opportunityApi_scenario002_run001_IT.feature:11 - could not find or read file: file:target/OpportunityID.txt"

Mr-Ho
  • 57
  • 1
  • 7

1 Answers1

1

This is hard to diagnose without knowing your Jenkins environment. Also there may be permissions problems so file creation may be restricted. In 0.9.4 we return a java.io.File object from the karate.write() method so you can try printing that etc.

But please, please read this because 99% of the time - you should never be writing files in Karate: https://stackoverflow.com/a/54593057/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • The Id that is returned from the response is used in the next scenario to append to an url, so that record can be used to be updated. The scenario after that uses the same id to access an url that deletes the record to keep the system clean. Is there a better approach? I've previously come across the link you have posted and decided that karate.write was an approach I should take after reading it...but then like the post says i'm inexperienced (so probably fall into the trap) and am still trying to figure out what is the best way of doing things. – Mr-Ho Jul 10 '19 at 10:53
  • @Mr-Ho you should *never* have a `Scenario` depend on another, and that is your mistake. it is already mentioned in the link, but also read this: https://github.com/intuit/karate#script-structure – Peter Thomas Jul 10 '19 at 11:13
  • 1
    Ok, sure i'll restructure my scenarios so they don't depend on other scenarios – Mr-Ho Jul 10 '19 at 12:58