# Artefact library

## Status to Bitbucket
*Available since 1.0*

Keep track of a step status in the CVS

### Signature

`utils.build_notify(currentBuild, String key, String title, Closure process, Closure error_eval = null)`

*Parameter*

- `currentBuild` is the meta object pointing to the current build
- `key` is used to uniquely identify a task within a build, It should not contain blankspace and non alphanumerical chars.
- `title` is the friendly title to be displayed to the user
- `process` is the wrapped steps to be taken for this step to complete. it is possible to **return a string** to override the step annotation, i.e: `Completed in 12 seconds`
- `error_eval` is the wrapped steps to be taken to evaluate an error annotation and **return it as a string** , i.e: `The Jira ticket was not approved` (Optional)

### Examples

Simple usage:

```groovy
utils.build_notify(currentBuild, 'my-tak-key', "My Task"){
    sh "echo proceed"
}
```

Step annotation usage:

```groovy
utils.build_notify(currentBuild, 'my-tak-key', "My Task"){
    if (my_var == "yes"){
        sh "echo proceed"
        return "Process was approved"
    } else {
        throw Exception("This wasn't approved")
    }
} {
    return "${my_other_var} was approved to proceed."
}
```

## Artifact generation
*Available since 1.1*

Create a new artifact that can be reused by a CD pipeline

### Signature

`artifacts.create_artifact(String path)`

*Parameter*

- `path` is the path to the **folder** from which the artifact needs to be created

### Examples

Simple usage using `utils.build_notify`:

```groovy
utils.build_notify(currentBuild, 'my-packaging-step', "Deliver artifact"){
    sh 'mkdir -p build && echo generated > build/output.txt'
    artifacts.create_artifact('build')
}
```


## Publish Docker Image
*Available since 1.X*

Create a image in a previously provisonned [ECR repository](http://foobar)

### Signature

`artifacts.publish_image(Image docker_image)`

*Parameter*

- `docker_image` is a Docker image built using the Docker library in Jenkins, i.e: `docker.build('myimage:itsversion')`

### Examples

Simple usage using `utils.build_notify`:

```groovy
utils.build_notify(currentBuild, 'my-packaging-step', "Deliver image"){
    def myimage = docker.build("myimage:myimmutabletag")
    artifacts.publish_image(myimage)
}
```

## Get current M2A version
*Available in 1.0 with library `artifacts`*

Get the current version for which the active pipeline is running

### Signature

`artifacts.get_version(currentBuild)`

*Parameter*

- `currentBuild` is the meta object pointing to the current build
- **Return value** is a string containing the version, i.e: `20.11~beta~352`

### Examples

Simple usage using `utils.build_notify` and `artifacts.create_artifact`:

```groovy
utils.build_notify(currentBuild, 'my-packaging-step', "Deliver artifact"){
    sh "mkdir -p build && echo 'Current build is ${artifacts.get_version(currentBuild)}' > build/output.txt"
    artifacts.create_artifact('build')
}
```

## Get current semantic version
*Available in 1.0 with library `artifacts`*

Get the current version for which the active pipeline is running

### Signature

`get_semantic_version()`

*Parameter*

- `env` is the global env object that can be accessed during the build
- `currentBuild` is the meta object pointing to the current build
- **Return value** is a string containing the semantic version, i.e: `1.2.3`

### Examples

Simple usage using `utils.build_notify`:

```groovy
utils.build_notify(currentBuild, 'my-packaging-step', "Deliver artifact"){
    sh "mkdir -p build && echo 'Current build is ${get_semantic_version(env, currentBuild)}' > build/output.txt"
    artifacts.create_artifact('build')
}
```
