The Snowflake CLI Plugin for Jenkins provides an installer for Snowflake CLI and a build wrapper for setting the Snowflake configuration file.
During a build, this plugin can:
- Install a specific version of Snowflake CLI on the agent.
- Add the executable path to the agent's PATH variable.
- Create a temporary directory for storing the configuration file and scripts.
- Export the
SNOWFLAKE_HOME
environment variable pointing to the temporary directory.
- In the System Configuration (Manage Jenkins > System Configuration > Tools), find the "Snowflake CLI Installations" section, and click "Add Snowflake CLI."
- Enter a label, e.g., "latest" — this label is used in Pipelines or displayed during Freestyle job configuration.
- Enter the desired version to be installed or specify another installation method.
Use the tools
directive within any pipeline
or stage
. For example:
pipeline {
// Run on an agent where we want to use Snowflake CLI
agent any
// Ensure the desired Snowflake CLI version is installed for all stages,
// using the name defined in the Global Tool Configuration
tools { snowflakecli 'latest' }
environment {
SNOWFLAKE_CONNECTIONS_MYCONNECTION_ACCOUNT = credentials('snowflake-account')
SNOWFLAKE_CONNECTIONS_MYCONNECTION_AUTHENTICATOR = 'SNOWFLAKE_JWT'
SNOWFLAKE_CONNECTIONS_MYCONNECTION_PRIVATE_KEY_RAW = credentials('snowflake-private-key-raw')
}
stages {
stage('Build') {
steps {
script {
// You can define the config.toml file in your Git repository and access it by checking out the code.
// Or you can use the following cat command as shown below to define it in the pipeline:
sh '''
cat <<EOF >> config.toml
default_connection_name = "myconnection"
[connections]
[connections.myconnection]
user = "ADMIN"
EOF
'''
// Optional WithCredentials wrapper to define a private key passphrase if private key is encrypted.
withCredentials([string(credentialsId: 'private_key_passphrase', variable: 'PRIVATE_KEY_PASSPHRASE')]) {
// Use a wrap directive, set $class as SnowflakeCLIBuildWrapper and add the parameter for the path to the configuration file in your repository.
// This wrapper copies the information of the input file and stores it to a temporal config.toml file.
wrap([$class: 'SnowflakeCLIBuildWrapper', configFilePath: 'config.toml']) {
sh 'snow connection list'
}
}
}
}
}
}
}
Similar as previous declarative pipeline, but it requires to set the PATH variable to snow executable.
node {
// Ensure the desired Snowflake CLI version is installed for all stages,
// using the name defined in the Global Tool Configuration
def root = tool type: 'snowflakecli', name: 'latest'
// Manually set the PATH variable to the snow executable.
withEnv(["PATH+SNOWFLAKECLI=${root}"]) {
// Use a wrap directive, set $class as SnowflakeCLIBuildWrapper and add the parameter for the path to the configuration file in your repository.
// This wrapper copies the information of the input file and stores it to a temporal config.toml file.
wrap([$class: 'SnowflakeCLIBuildWrapper', configFilePath: 'config.toml']) {
sh 'snow --version'
sh 'snow connection list'
}
}
}
- In a job's configuration, find the "Build environment" section.
- Select the "Install Snowflake CLI" checkbox.
- Select the name of a Snowflake installation from the drop-down.
- Choose inline or file mode:
- For file mode, enter the path to the
config.toml
. - For inline mode, enter the
config.toml
text.
- For file mode, enter the path to the
Licensed under the Apache License. See LICENSE for details.