Pipeline Utility Steps

findFiles: Find files in the workspace

Find files in the current working directory. The step returns an array of file info objects who's properties you can see in the below example.
Ex: def files = findFiles(glob: '**/TEST-*.xml') echo """${files[0].name} ${files[0].path} ${files[0].directory} ${files[0].length} ${files[0].lastModified}"""

glob (optional)

Ant style pattern of file paths that should match. If this property is set all descendants of the current working directory will be searched for a match and returned, if it is omitted only the direct descendants of the directory will be returned.

Type: String

readJSON: Read JSON from files in the workspace.

Reads a file in the current working directory or a String as a plain text JSON file. The returned object is a normal Map with String keys or a List of primitives or Map.

Example:


def props = readJSON file: 'dir/input.json'
assert props['attr1'] == 'One'
assert props.attr1 == 'One'

def props = readJSON text: '{ "key": "value" }'
assert props['key'] == 'value'
assert props.key == 'value'

def props = readJSON text: '[ "a", "b"]'
assert props[0] == 'a'
assert props[1] == 'b'
	

file (optional)

Path to a file in the workspace from which to read the JSON data. Data could be access as an array or a map.

You can only specify file or text, not both in the same invocation.

Type: String

text (optional)

A string containing the JSON formatted data. Data could be access as an array or a map.

You can only specify file or text, not both in the same invocation.

Type: String

readManifest: Read a Jar Manifest

Reads a Jar Manifest file or text and parses it into a set of Maps. The returned data structure has two properties: main for the main attributes, and entries containing each individual section (except for main).

Example:


            def man = readManifest file: 'target/my.jar'
            assert man.main['Version'] == '6.15.8'
            assert man.main['Application-Name'] == 'My App'
            assert man.entries['Section1']['Key1'] == 'value1-1'
            assert man.entries['Section2']['Key2'] == 'value2-2'
        

file (optional)

Optional path to a file to read. It could be a plain text, .jar, .war or .ear. In the latter cases the manifest will be extracted from the archive and then read.

You can only specify file or text, not both in the same invocation.

Type: String

text (optional)

Optional text containing the manifest data.

You can only specify file or text, not both in the same invocation.

Type: String

readMavenPom: Read a maven project file.

Reads a Maven project file. The returned object is a Model .

file (optional)

Optional path to the file to read. If left empty the step will try to read pom.xml in the current working directory.

Type: String

readProperties: Read properties from files in the workspace or text.

Reads a file in the current working directory or a String as a plain text Java Properties file. The returned object is a normal Map with String keys. The map can also be pre loaded with default values before reading/parsing the data.

Fields:
  • file: Optional path to a file in the workspace to read the properties from. These are added to the resulting map after the defaults and so will overwrite any key/value pairs already present.
  • text: An Optional String containing properties formatted data. These are added to the resulting map after file and so will overwrite any key/value pairs already present.
  • defaults: An Optional Map containing default key/values. These are added to the resulting map first.

Example:


        def d = [test: 'Default', something: 'Default', other: 'Default']
        def props = readProperties defaults: d, file: 'dir/my.properties', text: 'other=Override'
        assert props['test'] == 'One'
        assert props['something'] == 'Default'
        assert props.something == 'Default'
        assert props.other == 'Override'
        

defaults (optional)

java.lang.Object>

file (optional)

Type: String

text (optional)

Type: String

readYaml: Read yaml from files in the workspace or text.

Reads a file in the current working directory or a String as a plain text YAML file. It uses SnakeYAML as YAML processor. The returned objects are standard Java objects like List, Long, String, ...: bool: [true, false, on, off] int: 42 float: 3.14159 list: ['LITE', 'RES_ACID', 'SUS_DEXT'] map: {hp: 13, sp: 5}

Fields:
  • file: Optional path to a file in the workspace to read the YAML datas from.
  • text: An Optional String containing YAML formatted datas. These are added to the resulting object after file and so will overwrite any value already present if not a new YAML document

Examples:
With only one YAML document :


        def datas = readYaml text: """
something: 'my datas'
size: 3
isEmpty: false
"""
        assert datas.something == 'my datas'
        assert datas.size == 3
        assert datas.isEmpty == false
        
With several YAML documents :
        def datas = readYaml text: """
---
something: 'my first document'
---
something: 'my second document'
"""
        assert datas.size() == 2
        assert datas[0].something == 'my first document'
        assert datas[1].something == 'my second document'
        
With file dir/my.yml containing something: 'my datas' :
        def datas = readYaml file: 'dir/my.yml', text: "something: 'Override'"
        assert datas.something == 'Override'
        

file (optional)

Type: String

text (optional)

Type: String

touch: Create a file (if not already exist) in the workspace, and set the timestamp

Creates a file (if not already exist) and sets the timestamp.

file

The path to the file to touch.

Type: String

timestamp (optional)

The timestamp to set (number of ms since the epoc), leave empty for current system time.

Type: long

unzip: Extract Zip file

Extract a zip file in the workspace.

zipFile

The name/path of the zip file to extract.

Type: String

charset (optional)

Specify which Charset you wish to use eg. UTF-8

Type: String

dir (optional)

The path of the base directory to extract the zip to. Leave empty to extract in the current working directory.

Type: String

glob (optional)

Ant style pattern of files to extract from the zip. Leave empty to include all files and directories.

Type: String

read (optional)

Read the content of the files into a Map instead of writing them to the workspace. The keys of the map will be the path of the files read. E.g. def v = unzip zipFile: 'example.zip', glob: '*.txt', read: true String version = v['version.txt']

Type: boolean

test (optional)

Test the integrity of the archive instead of extracting it. When this parameter is enabled, all other parameters (except for zipFile) will be ignored. The step will return true or false depending on the result instead of throwing an exception.

Type: boolean

writeJSON: Write JSON to a file in the workspace.

Write a JSON file in the current working directory. That for example was previously read by readJSON.

Fields:
  • json: The JSON object to write.
  • file: Path to a file in the workspace to write to.

Example:


def input = readJSON file: 'myfile.json'
//Do some manipulation
writeJSON file: 'output.json', json: input
	

file

Type: String

json

Nested Choice of Objects

writeMavenPom: Write a maven project file.

Writes a Maven project file. That for example was previously read by readMavenPom.

Fields:
  • model: The Model object to write.
  • file: Optional path to a file in the workspace to write to. If left empty the step will write to pom.xml in the current working directory.

Example:


        def pom = readMavenPom file: 'pom.xml'
        //Do some manipulation
        writeMavenPom model: pom
        

model

org.apache.maven.model.Model

file (optional)

Type: String

zip: Create Zip file

Create a zip file of content in the workspace.

zipFile

The name/path of the zip file to create.

Type: String

archive (optional)

If the zip file should be archived as an artifact of the current build. The file will still be kept in the workspace after archiving.

Type: boolean

dir (optional)

The path of the base directory to create the zip from. Leave empty to create from the current working directory.

Type: String

glob (optional)

Ant style pattern of files to include in the zip. Leave empty to include all files and directories.

Type: String