Yes, I also asked this question on stack overflow. I’m a beginner in Jenkins, so I wonder if someone from the Julia community has some experience with this. The explanations from this community would be better for me to understand.
Its available in PATH but not installed in the Jenkins. I think I can run simple code in Jenkins now, like using CMD command julia E:\\sim_1\scripts\main.jl. But It still failed when it require some packages.
I have no idea about Jenkins, but this sounds like a project issue.
If your Julia project lives in E:/sim_1/ (i.e. Project.toml and Manifest.toml are located there), then use the --project flag when calling the script:
Is that the complete error message? I would like to suggest that you need to instantiate the environment in Jenkins, but then the error message should be longer and more helpful.
Yes, I only present the main message of the error. Obviously, this is because Jenkins agent has no access to the packages or the Project.toml. If I wrote using XXX in main.jl, the error message would be the same type.
I config Jenkins agent in this way:
cd /d E:\XXX\Jenkins\workspace\test\JenkinsSim
set JULIA_PROJECT=@.
set JULIA_NUM_THREADS=8
julia E:\XXX\Jenkins\workspace\test\JenkinsSim\scripts\main.jl
The error message would be:
Running as SYSTEM
Building in workspace E:\XXX\Jenkins\workspace\test
[test] $ cmd /c call C:\Windows\TEMP\jenkins78245134749799026.bat
E:\XXX\Jenkins\workspace\test>cd /d E:\XXX\Jenkins\workspace\test\JenkinsSim
E:\XXX\Jenkins\workspace\test\JenkinsSim>set JULIA_PROJECT=@.
E:\XXX\Jenkins\workspace\test\JenkinsSim>set JULIA_NUM_THREADS=8
E:\XXX\Jenkins\workspace\test\JenkinsSim>julia E:\XXX\Jenkins\workspace\test\JenkinsSim\scripts\main.jl
ERROR: LoadError: ArgumentError: Package DrWatson [634d3b9d-ee7a-5ddf-bec9-22491ea816e1] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
Stacktrace:
[1] _require(pkg::Base.PkgId)
@ Base .\loading.jl:1306
[2] _require_prelocked(uuidkey::Base.PkgId)
@ Base .\loading.jl:1200
[3] macro expansion
@ .\loading.jl:1180 [inlined]
[4] macro expansion
@ .\lock.jl:223 [inlined]
[5] require(into::Module, mod::Symbol)
@ Base .\loading.jl:1144
in expression starting at E:\XXX\Jenkins\workspace\test\JenkinsSim\scripts\main.jl:1
E:\XXX\Jenkins\workspace\test\JenkinsSim>exit 1
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
and my Project.toml is located in E:\XXX\Jenkins\workspace\test\JenkinsSim
So either in your main.jl you need to make sure that the project is instantiated, or modify your jenkins BAT script to instantiate it before you run the script:
cd /d E:\XXX\Jenkins\workspace\test\JenkinsSim
set JULIA_PROJECT=@.
set JULIA_NUM_THREADS=8
julia -E 'import Pkg; Pkg.instantiate()'
julia E:\XXX\Jenkins\workspace\test\JenkinsSim\scripts\main.jl
A word of advice is not to abbreviate too aggressively. Had you included the full line and the next we could immediately have told you what was the problem and how to solve it.
E:\XXX\Jenkins\workspace\test\JenkinsSim>julia -E import ‘Pkg; Pkg.instantiate()’
ERROR: syntax: incomplete: premature end of input
Stacktrace:
[1] top-level scope
@ none:1
E:\XXX\Jenkins\workspace\test\JenkinsSim>julia E:\XXX\Jenkins\workspace\test\JenkinsSim\scripts\main.jl
ERROR: LoadError: ArgumentError: Package DrWatson [634d3b9d-ee7a-5ddf-bec9-22491ea816e1] is required but does not seem to be installed:
Run Pkg.instantiate() to install all recorded dependencies.