\DronePluginSdkBuild

Build - A running build

This class represents a running Drone build and facilitates access to various exposed environment variables and plugin settings.

The following reference YAML will be used a reference for the following examples :

drone.example.yml

pipeline:
  test:
    image: phpdrone-example
    secrets: [ my_secret, other_secret ]
    my_simple_parameter: World
    my_parameter:
      something: yes
      something_else: probably
      another_level:
        - item1
        - item2
      a_boolean: true
      also_a_bool: yes
    my_array: [ an, array ]
    another_array:
      - machin
      - bidule
      - truc

Summary

Methods
Properties
Constants
getPluginParameter()
getSecret()
getCommit()
getRepo()
getNumber()
getEvent()
getStatus()
getLink()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
isJson()
No private properties found
N/A

Methods

getPluginParameter()

getPluginParameter(string  $parameter, boolean  $parseArray = true) : array|boolean|string|\stdClass

Gets a plugin parameter from Drone

The plugin can return an object if the key is complex ( eg: nested )

Getting a simple value :

// Get the build :
$build = new \DronePluginSdk\Build();

// Get some settings :
var_dump($build->getPluginParameter('my_simple_parameter'));

Result

[test:L0:0s] string(8) "World"

Getting a complex value :

// Get the build :
$build = new \DronePluginSdk\Build();

// Get some settings :
var_dump($build->getPluginParameter('my_parameter'));

Result

[test:L0:0s] object(stdClass)#2 (5) {
[test:L1:0s]   ["a_boolean"]=>
[test:L2:0s]   bool(true)
[test:L3:0s]   ["also_a_bool"]=>
[test:L4:0s]   bool(true)
[test:L5:0s]   ["another_level"]=>
[test:L6:0s]   array(2) {
[test:L7:0s]     [0]=>
[test:L8:0s]     string(5) "item1"
[test:L9:0s]     [1]=>
[test:L10:0s]     string(5) "item2"
[test:L11:0s]   }
[test:L12:0s]   ["something"]=>
[test:L13:0s]   bool(true)
[test:L14:0s]   ["something_else"]=>
[test:L15:0s]   string(8) "probably"
[test:L16:0s] }

Parameters

string $parameter

The parameter name as passed in the .drone.yml

boolean $parseArray

If set to false, , won't be exploded as array

Returns

array|boolean|string|\stdClass —

Parameter value, false if not found

getSecret()

getSecret(string  $secretName) : false|string

Retrieves a secret from Drone's secrets.

Parameters

string $secretName

Secret to retrieve

Returns

false|string —

Secret value, false if not fount

getCommit()

getCommit() : \DronePluginSdk\Commit

Gets current commit informations.

Returns

\DronePluginSdk\Commit

The current commit informations

getRepo()

getRepo() : \DronePluginSdk\Repo

Gets current repository informations.

Returns

\DronePluginSdk\Repo

The current repository informations

getNumber()

getNumber() : false|string

Gets the current build number.

Returns

false|string

getEvent()

getEvent() : false|string

Gets the current build event.

Returns

false|string

getStatus()

getStatus() : false|string

Gets the current build status ( `success` or `failure` ).

Returns

false|string

getLink()

getLink() : false|string

Gets the current build job link.

Returns

false|string

isJson()

isJson(string  $string) : boolean

Tries to detect a json string by parsing it.

Parameters

string $string

String to analyse

Returns

boolean