I have a Jenkinsfile that uses the shared Jenkins lib and calls method inside the groovy file defined below.
shared-jenkins-lib
|
|-----------vars
| |-------pipeline_script.groovy
|
|-----------scripts
|-------test_script.groovy
This is the structure of the library and pipeline_script.groovy has a method test which is called from jenkinsfile.
def test(){
dockerArgs = "--entrypoint /bin/bash"
dockerCommand = "`../scripts/test_script.sh`"
dockerOut = sh (script: "docker run ${dockerArgs} ${image} ${dockerCommand}", returnStatus: true)
}
I refer test_script.sh but doesn't seem to find the file in that location.
I am running jenkins within docker. What is the correct way to refer to the script
As stated in the docs of the shared libraries plugin, a library repo has a very specific structure. The root of the repo can have the following 3 folders:
+- src # Groovy source files
| +- org
| +- foo
| +- Bar.groovy # for org.foo.Bar class
+- vars
| +- foo.groovy # for global 'foo' variable
| +- foo.txt # help for 'foo' variable
+- resources # resource files (external libraries only)
| +- org
| +- foo
| +- bar.json # static helper data for org.foo.Bar
If you want to refer to a helper code/data from your library method, you should put it in the resources directory, and then you can retrieve it with the libraryResource step, also described in the docs.
You need to pass in the workflowscript object into test().
def test(workFlowScript wfs) {
...
wfs.sh ''
wfs.echo ''
wfs.withCredentials()
}
// your Jenkisnfile which call test()
test(this) // this is the instance of workFlowScript
Related
Suppose my directory is like this:
Project
|
|
| -- Jenkinsfile
|
| -- SubFolder1
|
| -- SubFolder2
I am using a script version of Jenkinsfile. I am wondering, how can I iterate through Project and get all folder names as one string?
If I do something like:
def filenames = [];
def dir = new File("$PWD");
dir.traverse(type: FILES, maxDepth: 0) {
filenames.add(it.getName())
}
It doesn't work since $PWD doesnt seem to be the actual current Project/ directory. Thanks!
${WORKSPACE} will point to the current running job local file system path.
See: http://localhost:8080/env-vars.html/ for environment variables list
Change localhost and port to your Jenkins instance.
I have several modules's directories. For each module, I have include (containing *.hrl files) and src (containing *.erl files) folder separeated. How can I share *.hrl file from a module to another without duplicating them?
With rebar, I added {erl_opts, [{i, "folderContainsIncludeFile"}]} and it worked.
But with rebar3, the compilation is failed by saying can't find include file "include/xx.hrl"
I take it then you don't have an umbrella project, you just have multiple directories at the same level, each one with its own project managed with rebar3.
Something like:
root_folder
|- project1
| |- src
| |- include
| | `- one.hrl
| `- rebar.config
|- project2
| |- src
| | `- two.erl
| |- include
| `- rebar.config
…
And you want to include one.hrl into two.erl.
If that's the case, you should consider one of these alternatives:
A. Moving to an umbrella project structure, like…
root_folder
|- rebar.config <<<<<<<< notice this file is here now
`- apps
|- project1
| |- src
| `- include
| `- one.hrl
|- project2
| |- src
| | `- two.erl
| `- include
…
B. Using individual repos for each project and configuring them as dependencies from each other. The structure is like the one you currently have, but now you have to add deps to rebar.config's. For instance, in our example, you should add the following line to project2's rebar.config:
{deps, [project1]}.
(if you manage to publish project1 in hex.pm)
C. Properly setting $ERL_LIBS so that it includes the paths where your apps are built with rebar3. Something like…
ERL_LIBS=$ERL_LIBS:/path/to/root_folder/project1/_build/lib:/path/to/root_folder/project2/_build/lib:…
Hope this helps :)
Our current project structure is as follows:
thirdparty(ws_root)
|_WORKSPACE
|_comp1
| |_BUILD
| |_src
| |_ a.c
| |_include
| |_ a.h
|_comp2
| |_BUILD
| |_src
| |_ b.c
| |_include
| |_ b.h
|_inc
| |_comp1
| |_a.h
| |_comp2
| |_b.h
Contents of a.c :
#include <comp1/a.h>
With our current build system the header file under thirdparty/comp1/include/a.h is staged with the following path:
thirdparty/inc/comp1/a.h
Here the thirdparty/inc folder is a global location where all header files in the workspace are staged under the respective components.
I would like to know if Bazel provides a mechanism by which we can stage the header files in a similar manner.
I'm not sure I understand, by "global location" you mean a folder in each library (library in the Bazel sense, you might call it component or package)? That's what I understood from the example. If that is the case, and each library just provides a -isystem include to all its dependents, that is possible in bazel, look for includes attribute.
According to documentation, it should be possible to include *.txt file with help/documentation:
(root)
+- src # Groovy source files
| +- org
| +- foo
| +- Bar.groovy # for org.foo.Bar class
+- vars
| +- foo.groovy # for global 'foo' variable/function
| +- foo.txt # help for 'foo' variable/function
+- resources # resource files (external libraries only)
| +- org
| +- foo
| +- bar.json # static helper data for org.foo.Bar
...
The vars directory hosts scripts that define global variables
accessible from Pipeline scripts. The basename of each *.groovy file
should be a Groovy (~ Java) identifier, conventionally camelCased. The
matching *.txt, if present, can contain documentation, processed
through the system’s configured markup formatter (so may really be
HTML, Markdown, etc., though the txt extension is required).
Unfortunately it hasn't worked for me by simply creating *.txt with some arbitrary content.
Am I missing something? Or does Global Shared Library doesn't shown documentation in usual Jenkins places:
Please note that the PipelineSyntax/Global Variables Reference page is ONLY updated when the pipeline's run is successful. And therefore ONLY for this pipeline (and not any others).
Here's a link!
I want to use gulp to copy and paste all HTML from a collection of src that are from a parent directory to a child directory, but keep their path
Project
+-- /Development
| +- gulpfile.js
|
+-- /Source
+- /ComponentA
| +- /DirA
| +- fileA.html
|
+- /ComponentB
| +- /DirB
| +- fileB.html
|
+- /ComponentC
+- /DirC
+- fileC.html
I need gulp to copy all HTML files to the relative paths into Development/public_html
Project
+-- /Development
+- gulpfile.js
|
+- /public_html
+- /ComponentA
| +- /DirA
| +- fileA.html
|
+- /ComponentC
+- /DirC
+- fileC.html
My gulp task
gulp.task('copyHTMLwrong', function() {
return gulp.src([
'../Source/ComponentA/**/*.html',
'../Source/ComponentC/**/*.html'
])
.pipe(gulp.dest('public_html'));
});
But I get (loose path):
Project
+-- /Development
+- gulpfile.js
|
+- /public_html
+- fileA.html
+- fileC.html
PS: I know if I use 'Source/**/*.html', will copy all files correctly and I'm sure I can also remove ComponentC using !, but i need to define each Component on my gulp.src, so I can compile for each website a group of files.
gulp.task('copyHTMLnotUseful', function() {
return gulp.src([
'../Source/**.*.html',
'!../Source/ComponentB/**/*.html'
])
.pipe(gulp.dest('public_html'));
});
I've tried set cwd or base, but didn't work either.
Thanks
I figured out how to use base to fix my Issue.
It's simple, just add a base with a __dirname, like so.
Just make sure you set inside path.resolve():
gulp.task('copyHTML', function() {
return gulp.src([
'../Source/ComponentA/**/*.html',
'../Source/ComponentC/**/*.html'
],
{base: path.resolve(__dirname + '/../Source')})
.pipe(gulp.dest('public_html'));
});