The following plugin provides functionality available through Pipeline-compatible steps. Read more about how to integrate steps into your Pipeline in the Steps section of the Pipeline Syntax page.

For a list of other such plugins, see the Pipeline Steps Reference page.

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

nodesByLabel: List of nodes by Label, by default excludes offline nodes.

Returns an array of node names with the given label.
  • label
    • Type: String
  • offline (optional)
    • Type: boolean

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.
  • interpolate: Flag to indicate if the properties should be interpolated or not. In case of error or cycling dependencies, the original properties will be returned.

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'
        
Example with interpolation:
        def props = readProperties interpolate: true, file: 'test.properties'
        assert props.url = 'http://localhost'
        assert props.resource = 'README.txt'
        // if fullUrl is defined to ${url}/${resource} then it should evaluate to http://localhost/README.txt
        assert props.fullUrl = 'http://localhost/README.txt'
        

  • defaults (optional)
      Nested Choice of Objects
  • file (optional)
    • Type: String
  • interpolate (optional)
    • Type: boolean
  • 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

sha1: Compute the SHA1 of a given file

Computes the SHA1 of a given file.

  • file

    The path to the file to hash.

    • Type: String

tee: Tee output to file

  • file
    • Type: String

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

Creates a file if it does not already exist, and updates 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
  • quiet (optional)

    Suppress the verbose output that logs every single file that is dealt with. E.g. unzip zipFile: 'example.zip', quiet: true

    • Type: boolean
  • 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.
  • pretty (optional): Prettify the output with this number of spaces added to each level of indentation.

Example:


def input = readJSON file: 'myfile.json'
//Do some manipulation
writeJSON file: 'output.json', json: input
// or pretty print it, indented with a configurable number of spaces
writeJSON file: 'output.json', json: input, pretty: 4
	

  • file
    • Type: String
  • json
      Nested Choice of Objects
  • pretty (optional)
    • Type: int

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

writeYaml: Write a yaml from an object.

Writes a yaml file in the current working directory from an Object or a String. It uses SnakeYAML as YAML processor. The call will fail if the file already exists.

Fields:
  • file: Mandatory path to a file in the workspace to write the YAML datas to.
  • data: A Mandatory Object containing the data to be serialized.
  • charset: Optionally specify the charset to use when writing the file. Defaults to UTF-8 if nothing else is specified. What charsets that are available depends on your Jenkins master system. The java specification tells us though that at least the following should be available:
    • US-ASCII
    • ISO-8859-1
    • UTF-8
    • UTF-16BE
    • UTF-16LE
    • UTF-16

Examples:


        def amap = ['something': 'my datas',
                    'size': 3,
                    'isEmpty': false]

        writeYaml file: 'datas.yaml', data: amap
        def read = readYaml file: 'datas.yaml'

        assert read.something == 'my datas'
        assert read.size == 3
        assert read.isEmpty == false
        

  • file
    • Type: String
  • data

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

Was this page helpful?

Please submit your feedback about this page through this quick form.

Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?

    


See existing feedback here.