# Using Jenkins to build versioned Mender artifacts

**URL:** <https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665>\
**Category:** General Discussions\
**Created:** [June 5, 2019, 6:04am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665 "2019-06-05T06:04:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![MBConsultingUK](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mbconsultinguk/32/243_2.png) [@MBConsultingUK](https://hub.mender.io/u/MBConsultingUK)\
**Post date:** [June 5, 2019, 6:04am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/1 "2019-06-05T06:04:48Z")

</div>

Hi Folks,

I didn’t want to hijack [Artifact versioning best practices?](https://hub.mender.io/t/artifact-versioning-best-practices/663/4) and [Howto: MENDER\_ARTIFACT\_NAME automatic setup for yocto build](https://hub.mender.io/t/howto-mender-artifact-name-automatic-setup-for-yocto-build/468) as whilst they are related, I’ve got a specific issue regarding building versioned artifacts with Jenkins.

The project I’m trying to build is [https://github.com/brocaar/lora-gateway-os](https://github.com/brocaar/lora-gateway-os), and at present the version is set in a `local.conf` file that is copied in at build time as follows:

```
stage('Build') { 
    steps {
        sh 'echo "The current path is ${PATH}"'
        sh 'mkdir -p lora-gateway-os/build'
        sh 'cp -a build/conf lora-gateway-os/build'
        sh 'source lora-gateway-os/oe-init-build-env build lora-gateway-os && env | grep MENDER && bitbake lora-gateway-os-base'
    }
}

```

The content of the local.conf file is as follows:

```
# Leave this to 'lora-gateway-os"
DISTRO = "lora-gateway-os"
DISTRO_VERSION="$(echo ${BRANCH_NAME} | sed -i 's/\//_/g')-${BUILD_ID}"
MENDER_ARTIFACT_NAME ?= "release-1"

# Select the target machine.
#
# Options are (per vendor configured in bblayers.conf):
#
# Vendor: raspberrypi
# * raspberrypi3
#
# Vendor: wifx
# * lorix-one-512-sd
# * lorix-one-sd
MACHINE = "raspberrypi3"

# Parallel executed tasks
BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()*2}"
PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count()*2}"

# Deploy dir
#
# This is the place where you will find the build artifacts.
TMPDIR = "${TOPDIR}/tmp/${VENDOR}/${MACHINE}"
DEPLOY_DIR = "${TMPDIR}/deploy/${DISTRO_VERSION}"
DEPLOY_DIR_IMAGE = "${DEPLOY_DIR}/images"

```

And the output of the `env | grep MENDER` shows the values that I would expect:

```
MENDER_ARTIFACT_NAME=lora-gateway-os-24
BB_ENV_EXTRAWHITE=ALL_PROXY BBPATH_EXTRA BB_NO_NETWORK BB_NUMBER_THREADS BB_SETSCENE_ENFORCE BB_SRCREV_POLICY DISTRO FTPS_PROXY FTP_PROXY GIT_PROXY_COMMAND HTTPS_PROXY HTTP_PROXY MACHINE MENDER_ARTIFACT_NAME NO_PROXY PARALLEL_MAKE SCREENDIR SDKMACHINE SOCKS5_PASSWD SOCKS5_USER SSH_AGENT_PID SSH_AUTH_SOCK STAMPS_DIR TCLIBC TCMODE all_proxy ftp_proxy ftps_proxy http_proxy https_proxy no_proxy null 

```

The problem is that when the image gets built, I get the following output:

```
BB_VERSION = "1.40.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "centos-7"
TARGET_SYS = "arm-oe-linux-gnueabi"
MACHINE = "raspberrypi3"
DISTRO = "lora-gateway-os"
DISTRO_VERSION = "2.0.0test4"
TUNE_FEATURES = "arm armv7ve vfp thumb neon vfpv4 callconvention-hard cortexa7"
TARGET_FPU = "hard"

```

and neither the DISTRO\_VERSION nor the ARTIFACT\_NAME are set to the values I’d expect from Jenkins.

I’m new to Mender and Yocto, so I’m pretty sure that this is a rookie error, but all and any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [June 5, 2019, 6:43am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/2 "2019-06-05T06:43:29Z")

</div>

Just my 2 cents:

> [@MBConsultingUK](#):
>
> sh ‘source lora-gateway-os/oe-init-build-env build lora-gateway-os && env | grep MENDER && bitbake lora-gateway-os-base’

I would try to change this line following:

```auto
sh 'source lora-gateway-os/oe-init-build-env build lora-gateway-os && bitbake -e lora-gateway-os-base | grep MENDER_ARTIFACT_NAME'

```

to really see if variable is set properly in console. My guess is that Jenkins somehow filter this variable (or it’s not properly exported → BTW how do you export MENDER\_ARTIFACT\_NAME variable) and then default will be used.

---

<div class="post-metadata">

**Author:** ![MBConsultingUK](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mbconsultinguk/32/243_2.png) [@MBConsultingUK](https://hub.mender.io/u/MBConsultingUK)\
**Post date:** [June 5, 2019, 7:21am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/3 "2019-06-05T07:21:22Z")

</div>

The variable is exported at the top of the Jenkins file:

```
environment {
    PATH = "${WORKSPACE}/lora-gateway-os/bitbake/bin:${PATH}"
    MENDER_ARTIFACT_NAME="lora-gateway-os-${BUILD_ID}"
    BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE MENDER_ARTIFACT_NAME"
}

```

Switching the grep to the end of the statement as you suggest returns the following:

```
# if [-z "${MENDER_ARTIFACT_NAME}"]; then
# bbfatal "Need to define MENDER_ARTIFACT_NAME variable."
# -n ${MENDER_ARTIFACT_NAME} \
# if [-z "${MENDER_ARTIFACT_NAME}"]; then
# bbfatal "Need to define MENDER_ARTIFACT_NAME variable."
# -n ${MENDER_ARTIFACT_NAME} \
        bbfatal \"Need to define MENDER_ARTIFACT_NAME variable.\" \
# $MENDER_ARTIFACT_NAME [3 operations]
MENDER_ARTIFACT_NAME="lora-gateway-os-2.0.0test4"
        bbfatal "Need to define MENDER_ARTIFACT_NAME variable."
```

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [June 5, 2019, 7:57am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/4 "2019-06-05T07:57:54Z")

</div>

> [@MBConsultingUK](#):
>
> MENDER\_ARTIFACT\_NAME=“lora-gateway-os-2.0.0test4”

This looks good to me or? What string do you see when build finish (and how do you inspect it)? Thanks.

---

<div class="post-metadata">

**Author:** ![MBConsultingUK](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mbconsultinguk/32/243_2.png) [@MBConsultingUK](https://hub.mender.io/u/MBConsultingUK)\
**Post date:** [June 5, 2019, 9:35pm UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/5 "2019-06-05T21:35:43Z")

</div>

Thanks for your time on this, it really is appreciated!

I’d expect to see `MENDER_ARTIFACT_NAME=lora-gateway-os-24` or similar.

The `2.0.0test4` is coming from the `DISTRO_VERSION` variable, rather than the variable that I’m setting at the top of the Jenkins job.

I’m hoping to be able to provide an Artifact that has the name `lora-gateway-os-<lora gateway os version>-<build id>` to mender so that I can deploy a specific build rather than having to rename the artifact each time before publishing.

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [June 6, 2019, 8:36am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/6 "2019-06-06T08:36:30Z")

</div>

> [@MBConsultingUK](#):
>
> MENDER\_ARTIFACT\_NAME=“lora-gateway-os-${BUILD\_ID}”

Please try to use `BUILD_NUMBER` instead `BUILD_ID`

---

<div class="post-metadata">

**Author:** ![MBConsultingUK](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mbconsultinguk/32/243_2.png) [@MBConsultingUK](https://hub.mender.io/u/MBConsultingUK)\
**Post date:** [June 6, 2019, 8:39pm UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/7 "2019-06-06T20:39:51Z")

</div>

ok, did that, it failed:

```
# $MENDER_ARTIFACT_NAME [3 operations]
MENDER_ARTIFACT_NAME="lora-gateway-os-2.0.0test4"
        bbfatal "Need to define MENDER_ARTIFACT_NAME variable."

```

Just about to try again and echo out that variable at the top of the job run

---

<div class="post-metadata">

**Author:** ![MBConsultingUK](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mbconsultinguk/32/243_2.png) [@MBConsultingUK](https://hub.mender.io/u/MBConsultingUK)\
**Post date:** [June 6, 2019, 8:43pm UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/8 "2019-06-06T20:43:29Z")

</div>

ok, so the script echos out the following:

```auto
+ echo '################'
################
+ echo 'The current path is /media/externalDrive/yocto/jenkins/jenkins-meta/jenkins-meta/workspace/teway-os_feature_add_jenkinsfile/lora-gateway-os/bitbake/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/pgsql-9.6/bin and the artifact name is lora-gateway-os-28'
The current path is /media/externalDrive/yocto/jenkins/jenkins-meta/jenkins-meta/workspace/teway-os_feature_add_jenkinsfile/lora-gateway-os/bitbake/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/pgsql-9.6/bin and the artifact name is lora-gateway-os-28
+ echo '######################'
######################

```

So the variable is set correctly at this point, but it doesn’t get picked up by Yocto, so I think this is a Yocto issue now.

Is it worth me continuing the conversation here, or should I move it over to the yocto forum/mailing list?

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [June 6, 2019, 8:46pm UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/9 "2019-06-06T20:46:06Z")

</div>

I found an issue. IIRC you’re using [this](https://github.com/brocaar/lora-gateway-os) repo. Problem is that it’s not picked up because it’s hardcoded in [L14](https://github.com/brocaar/lora-gateway-os/blob/8e54b980a88b82b8af27ad2dff42e3501dfce67b/meta/conf/layer.conf#L14) So I suggest to change this line to:

```auto
MENDER_ARTIFACT_NAME ?= "lora-gateway-os-${DISTRO_VERSION}"

```

and then your version from Jenkins will be picked.

---

<div class="post-metadata">

**Author:** ![MBConsultingUK](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mbconsultinguk/32/243_2.png) [@MBConsultingUK](https://hub.mender.io/u/MBConsultingUK)\
**Post date:** [June 6, 2019, 9:29pm UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/10 "2019-06-06T21:29:51Z")

</div>

OK, I’ve done that and it’s looking promising, thanks for spotting it.

I’ll check on the job in the morning as it can take up to two hours to run!

---

<div class="post-metadata">

**Author:** ![MBConsultingUK](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mbconsultinguk/32/243_2.png) [@MBConsultingUK](https://hub.mender.io/u/MBConsultingUK)\
**Post date:** [June 7, 2019, 5:30am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/11 "2019-06-07T05:30:11Z")

</div>

Brilliant, that worked, thanks! The images are building, now I just need to tweak a couple of scripts so the new version gets uploaded to Mender!

---

<div class="post-metadata">

**Author:** ![MarekBelisko](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/marekbelisko/32/33_2.png) [@MarekBelisko](https://hub.mender.io/u/MarekBelisko)\
**Post date:** [June 7, 2019, 7:11am UTC](https://hub.mender.io/t/using-jenkins-to-build-versioned-mender-artifacts/665/12 "2019-06-07T07:11:15Z")

</div>

Thanks for reporting back. 👍
