Search code examples
jenkinsjenkins-pipelineperforce

How to distinguish between auto triggered and perforce triggered jobs in Jenkins?


I have a build job that gets initiated by a perforce post submit trigger using an http post request. Something like:

curl --header 'Content-Type: application/json' 
     --request POST --user $JUSER:$JPASS 
     --data payload="{change:$CHANGE,p4port:\"$P4PORT\"}" 
     $JSERVER/p4/change

I also have the same job set to initiate on an automatic schedule process, twice a day

The idea of the perforce trigger compilation is just to make sure that the project is compilling wihtout errors.

The automated one I want it to do an extra step of packaging the project ready for user consumption (this takes signficant time so I don't want it to execut every time)

Things I tried so far

  • Try to pass an extra parameter on the post request, I can't find a way to make that work
--data payload="{change:$CHANGE,p4port:\"$P4PORT\",P4Triggered:1}"
  • Have two jobs, but I want continuous integration, so I want to be able to reuse the same workspace and.
  • Looked at jenkins environment variables to see if there is something that gives me this information, with no luck

Solution

  • So I ended up going with pipelines to make this work, that I really suggest people do. Just took one day of research and implementation to have something running in the end. And then I just added a stage with a when step

            stage('DEPLOY'){
            when {
                anyOf{
                    triggeredBy "TimerTrigger" //deploy if initiated by a timer or manually parameter
                    expression { params.deploy == true }
                }
            }
            steps{
                echo 'Deploying'
                bat returnStatus: true, script: '%WORKSPACE%\\TOOLS\\Deploy\\deploy.bat'
            }
        }
    

    This does the trick. It also has some cool visualization that shows you when something is being bypassed

    Pipeline Visualization

    That being said, I saw this online that might have made it work as well with a frestyle project and a perforce trigger

    --data 'json={"parameter":[{"name":"PARAMNAME","value":"agent-name"}]}&Submit=Build' 
    

    I might try it later.