-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to provide configuration file to JobDSL test? #103
Comments
Hi @dinbtechit. You should be able to pass env vars in here for testing: |
Hi @sheehan, Thanks for the quick turn around. Okay I'll try it out and let you know. On a side note - Ran into a similar issue with Credentials. Unit tests failing due to missing credentials. I want to pre-load a bunch of credentials for unit testing as seed jobs expects some credentials to be in place. Would you be able to provide some guidance on how to create credentials (ID, Username and password) for JobsDSL Unit Tests? Some sample code would be very helpful! :) |
Hi @sheehan , I haven't had any luck :( Are you able to provide me an example that is more specific to my example? Thanks really appreciate your help! |
Can you post your test code? Are you using JobScriptsSpec? |
Yes, I'm using JobScriptsSpec. Here is the my code.
|
I'm not 100% clear on your workflow, but does this work? File settings = new File('test_settings.xml')
settings.text = '<settings><name>mytest</name></settings>'
JobManagement jm = new JenkinsJobManagement(System.out, [CONFIG_FILE: settings.name], new File('.')) |
Let me try explaining this differently: I have a DSL job in my jobs directory. Its reading a xml file from the workspace. The path of the file is passed in as a environment variable - ${CONFIG_FILE}. jobs/MyDSLJob.groovy
Now, running the Gradle -> Test -> Fails (due to this following error)
So I need to somehow create the xml file in workspace using JobScriptsSpec for the Unit Test to Pass? Updated the JobScriptsSpec file to create the xml. (As shown in your above example) test/groovy/com.dslexample/JobScriptsSpec
But when I ran the Gradle ->Verification -> test (getting the same error). It looks like it is not able to find the environment variable ${CONFIG_FILE}
Does this makes sense? :) |
This truly works when I want to provide string values for the test. |
I have Jenkins jobs that uses the Config File Provider plugin to get settings project name, etc. Unfortunately, the gradle unit test fails as it is not able to find the file or property.
Caused by: javaposse.jobdsl.dsl.DslScriptException: (script, line 1) No such property: CONFIG_FILE for class: script.
However, I'm able to do it on the GUI (see screenshots below). But like see my Unit tests work as well.
Any help is massively appreciated.
The text was updated successfully, but these errors were encountered: