Using Jenkins to build versioned Mender artifacts

Hi Folks,

I didn’t want to hijack Artifact versioning best practices? and Howto: MENDER_ARTIFACT_NAME automatic setup for yocto build 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, 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!

Just my 2 cents:

I would try to change this line following:

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.

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."

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

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.

Please try to use BUILD_NUMBER instead BUILD_ID

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

ok, so the script echos out the following:

+ 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?

I found an issue. IIRC you’re using this repo. Problem is that it’s not picked up because it’s hardcoded in L14 So I suggest to change this line to:

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

and then your version from Jenkins will be picked.

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!

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!

1 Like

Thanks for reporting back. :+1: