Integrating OneSigner Folder-Watch With Jenkins for Automated Build Artifact Signing
You will learn how to configure a Jenkins pipeline to drop raw build artifacts into a OneSigner watched folder, letting the local Windows service automatically sign them using a hardware token without manual intervention.
Understanding the Architecture and Requirements
Automating code signing or document signing in a continuous integration pipeline typically fails when the signing key resides on a physical USB token. Since hardware tokens like YubiKey, SafeNet eToken, or ePass2003 require physical presence and interactive PIN entry, running a build agent in an isolated cloud container cannot access the key. OneSigner solves this by running as a Windows service on a dedicated local machine where your USB token is permanently plugged in.
The OneSigner service operates on Windows 10, Windows 11, or Windows Server 2019 and above. OneSigner runs as LocalSystem and initiates signing steps within the logged-on user's interactive session to communicate with the cryptographic provider. To ensure your build machine remains operational and retains its session after reboots, the OneSigner configuration GUI provides an Auto-Logon option on its General tab. Enabling auto-logon stores the password in plain text in the Winlogon registry key, allowing the machine to resume its interactive session automatically.
OneSigner offers several integration paths for CI/CD pipelines, including a REST API, command-line flags, an Azure Key Vault-compatible endpoint via OneSignTool, and watched folders. For many Jenkins setups, watched folders provide the simplest decoupled mechanism: your build agent generates an unsigned binary, copies it to a specific directory monitored by OneSigner, and picks up the signed artifact from the output location once processed.
Configuring Watched Folders in the OneSigner GUI
Before configuring your Jenkins job, you must set up a signing profile and bind it to a source folder in the OneSigner configuration application. Signing profiles determine whether the operation applies to a PDF or a code-signing task, which certificate thumbprint to use, and how files are handled.
Open the OneSigner configuration GUI on the machine hosting your USB hardware token. Create a new signing profile of type codesign. Select your token's certificate from the list, provide the correct PIN so the service can automate access via PKCS#11 or CSP/KSP, and configure your source directory path, such as C:\Builds\UnsignedArtifacts. When you save the profile, OneSigner begins monitoring that source folder for incoming files.
Note that a rejected PIN is not retried automatically within the same job to prevent locking your hardware token after consecutive failed attempts. However, every new job uses the saved PIN again. If you update your token's PIN on the physical device, you must update the saved PIN in your OneSigner profile immediately; otherwise, a stale saved PIN will eventually lock your token across repeated build runs. For more context on handling hardware tokens cleanly, review the OneSigner configuration guide.
Writing the Jenkins Pipeline Stage
With the watched folder active on your signing host, your Jenkins pipeline needs to build the artifact, transfer it to the monitored directory, and wait for the signed file to appear. Depending on whether your Jenkins controller runs on the same physical Windows machine or a remote node, file transfer can be executed via a local file copy or a network share.
Below is a declarative Jenkinsfile snippet demonstrating how to compile a Windows executable and drop it into the watched folder:
pipeline {
agent { label 'windows-signing-host' }
stages {
stage('Build') {
steps {
bat 'dotnet publish -c Release -r win-x64 --self-contained true -o ./publish'
}
}
stage('Sign Artifact') {
steps {
script {
// Copy unsigned binary to OneSigner watched source folder
bat 'copy /Y .\publish\MyApp.exe C:\Builds\UnsignedArtifacts\MyApp.exe'
// Wait for OneSigner to process and output the signed file
// Adjust timeout and polling interval based on your build volume
powershell '''
$timeout = 60
$elapsed = 0
$signedFile = "C:\Builds\SignedArtifacts\MyApp.exe"
while (-not (Test-Path $signedFile)) {
Start-Sleep -Seconds 2
$elapsed += 2
if ($elapsed -ge $timeout) {
throw "Signing timeout reached."
}
}
'''
}
}
}
}
}
If your Jenkins setup requires direct programmatic control rather than directory monitoring, you can invoke the REST API endpoints instead. The service exposes POST requests such as /api/codesign and /api/signing/sign secured by Bearer tokens, or you can leverage OneSignTool with AzureSignTool syntax for command-line automation. To explore alternative pipeline strategies, consult the OneSigner REST API documentation.
Handling Logs, Diagnostics, and Troubleshooting
When automated builds fail to sign, diagnosing the root cause requires checking the correct log files located on the signing host. The Windows service writes operational entries directly to the Windows Event Log under the Application log. Detailed signing history is recorded in tab-separated files located at C:\OneSigner\app\logs\signing-YYYY-MM-DD.log and can also be viewed within the portal under Management → Logs.
If you encounter unexpected behavior during CLI interactions or API calls, you can enable verbose output by setting the environment variable:
set ONESIGNER_CLI_LOG=info
Common failures include missing timestamp server URLs, expired certificates, or incorrect file hashes. For code signing operations, Windows Authenticode supports applying an RFC 3161 timestamp to ensure signatures remain valid after the certificate expires. For further guidance on resolving cryptographic errors, review the OneSigner portal logs.
Next Steps
Ensure your OneSigner Windows service (OneSignerService) is running and that your auto-logon configuration is active to prevent session lockouts. To evaluate your setup before pushing to production, review your local licensing or check your signing history in the portal.