Automate the development, testing and execution of SAS (CAS) code in SAS Viya 3.5 with Git and Jenkins. Learn how to create a simple Jenkins pipeline and the basics of Jenkins pipeline syntax, with a simple example to load flat files in CAS.
Jenkins is an open source automation server. With a Jenkins file, also stored in GitLab (or GitHub), Jenkins can run code (SAS, shell, etc.) on hosts called agents. SAS Viya can be an agent.
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
A continuous integration / continuous delivery (CI/CD) pipeline is a sequence of events or jobs that can be executed.
CI continuous integration = version control.
CD continuous delivery = get software from version control right through to your users and customers.
CI/CD Business Benefits: Accelerate time-to-value. Reduce costs. Experimentation = innovation. Data-driven decision making. Quality.
Jenkins is one of the best known open source automation server for CI/CD.
By default, Jenkins will attempt to run builds (jobs, code) wherever it is installed.
Jenkins can be directed to run on other hosts, called agents in "Jenkins-speak". This capacity is one powerful feature. SAS Viya can be “recruited” as a Jenkins agent.
For Jenkins, the agent code name, the label viyahost matters. On this SAS Viya machine, Jenkins must use a working folder to do its thing (such as /opt/sas/devops/workspace/ ).
Jenkins will launch an agent. It will then connect to the host indicated, with the credentials given. That means Jenkins will run all commands (and SAS programs) on the Viya machine, as the user specified.
GitLab is a web-based DevOps lifecycle tool that provides a Git-repository manager and version control.
The SAS program we want to automate with Jenkins, 080_load_CAS.sas is stored in a GitLab project.
The necessary git commands were discussed in a previous post.
The script initiates a CAS session and loads a few files. I found out that you must use casauto if you want to run the CAS program in batch (which you must with Jenkins).
cas casauto;
* source caslib;
%let DM_src=DM;
* target caslib;
%let DM_TRG=Public;
* Your UserID;
%let userid=Your course assigned user ID (e.g. gatedemoxxx);
* Load files into target caslib;
* Drop first;
proc casutil incaslib="DM_TRG";
droptable casdata="&userid._catcode" quiet;
droptable casdata="&userid._mailorder" quiet;
droptable casdata="&userid._products" quiet;
droptable casdata="&userid._customers" quiet;
quit;
* Load;
proc casutil incaslib="&;DM_SRC" outcaslib="&DM_TRG";
load casdata="catcode.csv" casout="&userid._catcode" copies=0 promote;
load casdata="mailorder.csv" casout="&userid._mailorder" copies=0 promote;
load casdata="products.csv" casout="&userid._products" copies=0 promote;
load casdata="customers.csv" casout="&userid._customers" copies=0 promote;
quit;
cas casauto terminate;
The Jenkins Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines "as code". To define a pipeline, go to Jenkins > New Item (top left).
Choose Pipeline.
Indicate where the Jenkins pipeline definition (Jenkins file) can be found. In this example, the Jenkins file is stored in GitLab.
The definition of a Jenkins Pipeline is typically written in a file, called Jenkinsfile. The Jenkins pipeline syntax is written in Apache Groovy.
In the GitLab project create a New file, called Jenkinsfile (or create it locally and push it remotely):
pipeline {
agent { label 'viyahost'}
stages {
stage('Clone GIT on SAS Viya') {
steps {
sh 'echo "Hello " `logname`'
}
}
stage('Copy source files') {
steps {
sh 'cp /opt/sas/devops/workspace/SBXBOT-PSGEL250-devops-applied-to-sas-viya-3.5/Data-Management/source-data/* /gelcontent/demo/DM/data/'
}
}
stage('Load in CAS') {
steps {
sh '/opt/sas/spre/home/SASFoundation/sas -autoexec "/opt/sas/viya/config/etc/workspaceserver/default/autoexec_deployment.sas" /opt/sas/devops/workspace/SBXBOT-PSGEL250-devops-applied-to-sas-viya-3.5/Data-Management/scripts/080_load_CAS.sas -log /tmp/080_load_CAS.log'
}
}
}
post {
always {
echo 'Job Done!'
}
}
}
A few words on the Jenkins file syntax:
Driven by the Jenkinsfile above, Jenkins will build a pipeline to:
stage('Copy source files') {
steps {
sh 'cp /opt/sas/devops/workspace/SBXBOT-PSGEL250-devops-applied-to-sas-viya-3.5/Data-Management/source-data/* /gelcontent/demo/DM/data/'
}
}
stage('Load in CAS') {
steps {
sh '/opt/sas/spre/home/SASFoundation/sas -autoexec "/opt/sas/viya/config/etc/workspaceserver/default/autoexec_deployment.sas" /opt/sas/devops/workspace/SBXBOT-PSGEL250-devops-applied-to-sas-viya-3.5/Data-Management/scripts/080_load_CAS.sas -log /tmp/080_load_CAS.log'
}
}
}
post {
always {
echo 'Job Done!'
}
}
I am using Blue Ocean, a Jenkins plug-in, to run and visualize pipelines.
Your pipeline will show off previous builds, if any.
Run the pipeline.
If all was set up correctly, you would see the result, in the latest run.
The Jenkins file has been converted in a pipeline, containing the stages described in the Jenkinsfile.
You can consult the individual steps, look at their status and the logs.
In SAS Viya, you will see the loaded tables in CAS:
We automated the loading of a CAS table with SAS Viya 3.5, Jenkins and GitLab. A Jenkins pipeline was defined, with the SAS Viya machine as the agent. The Jenkinsfile containing the Jenkins syntax was stored in GitLab, along with the SAS program to be executed. Finally, we ran the Jenkins pipeline, analyzed the results and confirmed visually the results in CAS.
More will follow: how to introduce tests, parallelize stages, surface detailed logs or import SAS content, such as SAS Data Studio Plans or SAS Visual Analytics reports.
Mark Thomas, Rob Collum, Stephen Foerster.
Thank you for your time reading this post. Please comment and share your experience with Jenkins and SAS.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.