# How to run julia code that depends on other packages in Jenkins？

**URL:** <https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 1, 2023, 4:06pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388 "2023-01-01T16:06:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 1, 2023, 4:06pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/1 "2023-01-01T16:06:03Z")

</div>

Hi guys, I try to run some codes with the help of Jenkins. OS is win10.

I tried this command but failed:

```julia
cd E:\\sim_1\scripts
set JULIA_NUM_THREADS=8
julia E:\\sim_1\scripts\main.jl

```

error says that julia is not a command, but I checked the system path and also run the above code in CMD, it works well.

Are there any tutorials on this issue? I searched around and couldn’t find it.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [January 2, 2023, 6:37am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/2 "2023-01-02T06:37:21Z")

</div>

This is more a Jenkins than a Julia related question. Better ask this on “stack overflow”. See for example [delphi - Why is Jenkins ignoring the %PATH% variable when using MSBuild? - Stack Overflow](https://stackoverflow.com/questions/5735241/why-is-jenkins-ignoring-the-path-variable-when-using-msbuild)

---

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 2, 2023, 6:48am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/3 "2023-01-02T06:48:53Z")

</div>

Thanks!

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.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 2, 2023, 12:18pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/4 "2023-01-02T12:18:56Z")

</div>

Is julia installed in the jenkins worker and available in PATH?

---

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 2, 2023, 3:01pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/5 "2023-01-02T15:01:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![p-gw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/p-gw/32/210518_2.png) [@p-gw](https://discourse.julialang.org/u/p-gw)\
**Post date:** [January 2, 2023, 3:37pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/6 "2023-01-02T15:37:31Z")

</div>

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:

```julia
julia --project=E:/sim_1 E:/sim_1/scripts/main.jl

```

or change directory beforehand

```julia
cd E:/sim_1
julia --project=@. scripts/main.jl

```

---

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 2, 2023, 4:02pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/7 "2023-01-02T16:02:08Z")

</div>

Thank you!  
I have tried to set environment, and it also works in CMD.  
While in Jenkins, error still comes like this ：

```julia
ERROR: LoadError: ArgumentError: Package DrWatson [634d3b9d-ee7a-5ddf-bec9-22491ea816e1] is required

```

and I am pretty sure that `DrWatson` is included in the Project.toml.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 2, 2023, 5:57pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/8 "2023-01-02T17:57:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 3, 2023, 4:32am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/9 "2023-01-03T04:32:36Z")

</div>

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:

```julia
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:

```julia
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`

```julia
name = "JenkinsSim"
authors = ["Yibo"]

[deps]
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
DrWatson = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
DynamicalSystems = "61744808-ddfa-5f27-97ff-6e42cc95d634"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"

[compat]
julia = "1.8.4"

```

Should I install packages in the Jenkins agent? and how can I do that?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 3, 2023, 5:58am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/10 "2023-01-03T05:58:54Z")

</div>

> [@YiboXia](#):
>
> Should I install packages in the Jenkins agent? and how can I do that?

Yes, the error message already tells you that:

> [@YiboXia](#):
>
> ```julia
> 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.
> 
> ```

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:

```BAT
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

```

---

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 3, 2023, 7:23am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/11 "2023-01-03T07:23:34Z")

</div>

Thanks! really helpful!

> julia -E ‘import Pkg; Pkg.instantiate()’

It doesn’t work but I add ` import Pkg; Pkg.instantiate()` to the head of `main.jl` and it works!

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 3, 2023, 8:08am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/12 "2023-01-03T08:08:57Z")

</div>

> [@YiboXia](#):
>
> Yes, I only present the main message of the error.

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.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 3, 2023, 11:18am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/13 "2023-01-03T11:18:59Z")

</div>

> [@YiboXia](#):
>
> It doesn’t work but I add

That should work though 🤔 It’s doing the exact same thing. Do you get an error? What exactly happens?

---

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 3, 2023, 11:48am UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/14 "2023-01-03T11:48:28Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 3, 2023, 3:35pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/15 "2023-01-03T15:35:28Z")

</div>

> [@YiboXia](#):
>
> E:\XXX\Jenkins\workspace\test\JenkinsSim\>julia -E import ‘Pkg; Pkg.instantiate()’

Looks like you copied wrong - those apostrophes are at the wrong place. Note that in the code I posted they enclose the `import` too.

---

<div class="post-metadata">

**Author:** ![YiboXia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yiboxia/32/50734_2.png) [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Post date:** [January 3, 2023, 4:37pm UTC](https://discourse.julialang.org/t/how-to-run-julia-code-that-depends-on-other-packages-in-jenkins/92388/16 "2023-01-03T16:37:33Z")

</div>

Really thank you, for correction!
