jenkinsci / plasticscm-plugin

A plugin for Jenkins to be able to use Plastic SCM
MIT License
16 stars 31 forks source link

PLASTIC_ environment variavbles are resulting as null when used with checkout #42

Closed krishna3008 closed 1 year ago

krishna3008 commented 3 years ago

Issue

I am using pipeline and checkout plastic via Checkout SCM

When I tried to call the plastic env variables the result is being null

Commands used

checkout([$class: 'PlasticSCM', cleanup: 'MINIMAL', directory: '', selector: '''repository "default" path "/" smartbranch "/main"''', useMultipleWorkspaces: false])

echo "Running ${env.PLASTICSCM_CHANGESET_ID} on ${env.PLASTICSCM_BRANCH}"

Note: checkout is been used with actual values

Output

Running null on null

knapsu commented 3 years ago

Jenkins Pipelines operates differently than standard Jenkins jobs. You are getting null because checkout(...) method does not fill the Groovy env object on it's own.

Try this instead (using modern syntax instead of a selector which is considered obsolete)

def scmVars = cm(branch: '/main', repository: 'default', server: '......', directory: '')
if (!scmVars.PLASTICSCM_CHANGESET_ID) {
  error('Missing Plastic SCM environment variables')
}
krishna3008 commented 3 years ago
def scmVars = cm(branch: '/main', repository: 'default', server: '......', directory: '')
if (!scmVars.PLASTICSCM_CHANGESET_ID) {
  error('Missing Plastic SCM environment variables')
}

@knapsu I have tried the above and checkout is failing every time In the console also I am not seeing the output as similar to the checkout format I am using before.

mig42 commented 2 years ago

Hi @krishna3008 , what's the failure you're getting in the checkout after following @knapsu's suggestions?

krishna3008 commented 2 years ago

Hi @mig42

I have executed as mentioned and checkout is happening but in the end, I am getting an error as

"cm" "log" "cs:-1" "--xml=/h/w/output_5873061305059926149.xml" "--encoding=utf-8" 
The specified changeset cs:-1 does not exist.

C:\h\w>exit
Executing cmd script inside container prsrr of pod gen32-w5qlw-869zc-sk6s7
Microsoft Windows [Version 10.0.17763.1757]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\h>Executing command: "cm" "log" "cs:-1" "--xml=/h/w/output_5873061305059926149.xml" "--encoding=utf-8"

Actually, I am running in docker Is there any limitation to use the plastic Jenkins command in docker environment

mig42 commented 2 years ago

Hi @krishna3008 , there isn't any limitation to run the Plastic SCM plugin for Jenkins in a docker environment. However, we need more information about this case to understand how to reproduce it and successfully troubleshoot it. This includes the full output of the build, too (not just excerpts).

krishna3008 commented 2 years ago

Hi @krishna3008 , there isn't any limitation to run the Plastic SCM plugin for Jenkins in a docker environment. However, we need more information about this case to understand how to reproduce it and successfully troubleshoot it. This includes the full output of the build, too (not just excerpts).

Hi @mig42 In my build I ran only the plastic checkout and in the log all files are downloaded but at the status update part I see the error as the screenshot I shared. Please inform the details of extra information you were asking

mig42 commented 2 years ago

Hi @krishna3008, I was kindly asking for build logs for the job that fails and an example of pipeline that causes the issue. Otherwise we won't be able to help and we'll eventually have to close the issue.

Additionally, is there a reason why you're using the pipeline command checkout() instead of our own cm()?

krishna3008 commented 2 years ago

Hi @mig42

I am checking with the cm() only I can't directly share the entire build log because it is with the client I am working for, and can't disclose his details.

So, for the details, I have shared the exact error step output text instead of the snapshot of it. If you are asking for the logs from the plastic client, those are difficult since the build is in windows dockers. If you are able to say the exact log path I will try to get them.

To be clear again

knapsu commented 2 years ago

I am using this plugin via Jenkins in the windows docker, not the actual machine

It seems that variables are not present in the Docker environment. How to pass the env variables to the docker process depends on the way you run it.

If you are running it with directly with your own command then consider using a command argument -e, --env or --env-file

If you are running it as Pipeline script block then check the step documentation that you are using https://www.jenkins.io/doc/book/pipeline/docker/ https://www.jenkins.io/doc/pipeline/steps/

krishna3008 commented 2 years ago

It seems that variables are not present in the Docker environment. How to pass the env variables to the docker process depends on the way you run it.

Can I know which environment variables are referring and As I told When I used direct CLI commands, this error is not coming.

If you are running it with directly with your own command then consider using a command argument -e, --env or --env-file

If you are running it as Pipeline script block then check the step documentation that you are using https://www.jenkins.io/doc/book/pipeline/docker/ https://www.jenkins.io/doc/pipeline/steps/

Yes, I am running this in a pipeline script and I used the pipeline syntax tool to generate my cm() command.

I wrote my bat script in the pipeline to perform the checkout, But we need to publish the changes and plastic checkout information on the build dashboard which the plugin is doing properly.