Skip to content

Instantly share code, notes, and snippets.

@solvingj
solvingj / redirect_subprocess_via_descriptors.py
Last active March 18, 2022 14:34
Redirect stdout of all subprocess invocations in realtime implicitly without passing subprocess.PIPE or capture_output.
import os
import subprocess
import sys
from contextlib import ExitStack
if __name__ == '__main__':
# For each process, there is a table of file descriptors (pfd).
# Each entry contains an ID number, and a reference to an ID in the
# system open file table (soft)
@solvingj
solvingj / cmake_user_paths.py
Created April 21, 2021 13:38
A custom Conan generator which produces cmake paths based on environment variables
# This is intended to demonstrate a proof-of-concept
# for users/callers of Conan to easily override
# conan-generated paths for dependencies.
# The purpose was to show how users could manually
# implement "editable" packages.
# It works, however, sadly, not the way intended.
# Environment variables from profiles are not
# made available in generators. os.getenv() returns
# only environment variables set in the outer shell.
@solvingj
solvingj / Dockerfile
Created December 10, 2020 04:55
Jenkins dockerfile plugins won't download
FROM jenkins/jenkins:2.263.1-lts-centos
USER root
RUN rm -f /etc/yum.repos.d/github_git-lfs.repo
RUN yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
@solvingj
solvingj / jenkins.yaml
Last active July 10, 2020 02:32
Jenkins CASC for organization folder: Whats wrong?
jobs:
- script: >
organizationFolder('gitbucket') {
description("All repos with Jenkinsfiles discovered on gitbucket")
displayName("gitbucket")
organizations {
github {
apiUri("http://gitbucket/api/v3")
credentialsId('DEMO_GIT_CREDS')
repoOwner('root')
package demo.ci.arg
import com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest
import org.junit.Before
import org.junit.jupiter.api.Test
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource
class ConanArgsJPUSpec extends DeclarativePipelineTest {
@Override
@solvingj
solvingj / withIndex.txt
Last active June 14, 2020 16:40
Iterable withIndex behavior discrepancy on Jenkins
// Run this in a Jenkins step
String jsonStr = "['zero', 'one', 'two']"
JSONArray jsonArray = new JsonSlurper().parseText(jsonStr) as JSONArray
jsonArray.withIndex().each{Object str, Integer idx -> currentBuild.echo("${idx.toString()} : ${str}")}
// OUTPUT from jenkins
// [Pipeline] echo
// null : [zero, 0]
// [Pipeline] echo
// null : [one, 1]
jobs:
- script: >
multibranchPipelineJob('libA') {
branchSources {
git {
id = 'libA'
credentialsId = 'GIT_CREDS'
remote('http://172.17.0.3:8080/git/root/libA.git')
}
}
@solvingj
solvingj / job.log
Created May 7, 2020 17:35
casc job first run failure stacktrace
ranch indexing
> /usr/local/bin/git rev-parse --is-inside-work-tree # timeout=10
ERROR: Workspace has a .git repository, but it appears to be corrupt.
hudson.plugins.git.GitException: Error performing git command: /usr/local/bin/git rev-parse --is-inside-work-tree
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2437)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2360)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2356)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1916)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1928)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.hasGitRepo(CliGitAPIImpl.java:343)
@solvingj
solvingj / CpsScriptMock.groovy
Created May 6, 2020 17:30
Extending CpsScript Impossible?
// Fails to compile with:
// CpsScriptMock.java:15: error: unreported exception IOException; must be caught or declared to be thrown
// But i'm throwing it right?
package demo.ci
import org.jenkinsci.plugins.workflow.cps.CpsScript
class CpsScriptMock extends CpsScript {
CpsScriptMock() throws IOException {
}
@solvingj
solvingj / tasks.vs.json
Last active June 20, 2019 16:32
Current Schema of Tasks.vs.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"default": {
"type": "object",
"properties": {
"taskName": {
"type": "string"
},
"taskLabel": {