Jenkins Pipeline Influx - Error: influxDbPublisher: not found

Hi,

I would like some help please, I’m new to the community.

I currently have a Pipeline in Groovy in the Library (I didn’t develop it and I have no knowledge in Groovy) declared in the “Configure System”.

The InfluxDB Plugin was installed in Jenkins (InfluxDB Plugin Version3.4).

Up to this point ok.

Using a declarative-type pipeline just for testing, I can run normally and I was able to record information in Influx.

...
   stages {
        stage('STEP 1') {
            steps {
                script {
                    echo "TEST_01"
                    influxDbPublisher jenkinsEnvParameterTag: 'KEYTEST=DEV', selectedTarget: 'InfluxDB'
                }
            }
        }

However, using the official Pipeline in Groovy we are taking the error.

package XX.com.XXX.deploy

class DeployDev {

    def call (jenkins) {
        
        String credentials
        String cluster
        def ecrLogin

        String DOCKER_TAG = "${jenkins.env.APP_VERSION}.${jenkins.env.GIT_COMMIT}.${jenkins.env.BUILD_NUMBER}"

        if (jenkins.env.SKIP_BUILD_FOR_TAG?.trim()) {
            DOCKER_TAG = jenkins.env.SKIP_BUILD_FOR_TAG
        }

        jenkins.podTemplate(
            containers: [
                jenkins.containerTemplate(
                    name: 'helm', 
                    image: 'XXXXXXXXXXXXXXXXXXXXXXX', 
                    ttyEnabled: true, 
                    command: 'cat', 
                    alwaysPullImage: false
                ),
                jenkins.containerTemplate(
                    name: 'aws-cli', 
                    image: 'XXXXXXXXXXXXXXXXXXXXXXX', 
                    ttyEnabled: true, 
                    command: 'cat', 
                    alwaysPullImage: false
                )
            ],    
            yamlMergeStrategy: jenkins.merge(),
            workspaceVolume: jenkins.persistentVolumeClaimWorkspaceVolume(
                claimName: "pvc-workspace-${jenkins.env.JENKINS_AGENT_NAME}",
                readOnly: false
            )
        ) {
            jenkins.node(jenkins.POD_LABEL){
                jenkins.container('aws-cli'){
                    ecrLogin = jenkins.ecrLogin(registryIds: ['XXXXXXXXXX'])
                    def token = jenkins.sh label: 'ECR login',
                                           script: "aws ecr get-login-password",
                                           returnStdout: true
                    ecrLogin = token
                }

                jenkins.container('helm') {
                    jenkins.echo "Deploy Step"
                    jenkins.withKubeConfig([
                        credentialsId: "XXXXXXXXXXXXXX",
                        serverUrl: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                    ]) {
          """
                        jenkins.sh label: 'Collecting metrics', 
                            script: """
                                influxDbPublisher jenkinsEnvParameterTag: 'KEYTEST=DEV', selectedTarget: 'InfluxDB'
                            """
                    }
                    jenkins.echo 'Deploy successful! 🌟'
                }
            }
        }
    }
}

Erro:

/home/jenkins/agent/workspace/XXX/DemoInflux@tmp/durable-fd88fcc0/script.sh: line 2: influxDbPublisher: not found

What it looks like, that in Pipeline Groovy mode, the library is not being loaded (I’m not sure nor knowledge in Groovy language), if you can help please.

whats this random quotes about?

You are calling a groovy function (influxDbPublisher) inside your shell script (sh script: “”)
If you remove the sh/script stuff so its just

{
                                influxDbPublisher jenkinsEnvParameterTag: 'KEYTEST=DEV', selectedTarget:  ""                           
                    }

Thanks for the feedback.

There was an attempt, but without success.

The Influx line was placed outside the script, but it returns the error below

Error:

you prefix all your pipeline “commands” with jenkins., so you’ll probably need to do that here.