➡️ "Jenkins Pipeline Environment Variables - The Definitive Guide" blog post can be found here: e.printstacktrace.blog/jenkins-pipeline-environment-variables-the-definitive-guide/ Timestamps: 00:00 Introduction 00:29 Listing env variables 01:34 Accessing env variables 03:20 Setting env variables 07:45 Overriding env variables 09:50 Using env variable as boolean 12:18 Capturing the output from other steps 14:08 Dealing with null in the env variable
@szymonstepniak3 жыл бұрын
@Eduard FLORINESCU This is Blue Ocean UI - www.jenkins.io/projects/blueocean/
@yonatanhuber94643 жыл бұрын
man, I was breaking my head over this for hours. THANK YOU
@szymonstepniak3 жыл бұрын
Thank you for your kind words, Yonatan! Have a good day!
@harsimranjitsingh5912 жыл бұрын
Some one please give this guy a medal for the awesome video ❤️👍
@demianpelos3 жыл бұрын
Very simple and easy to follow. Now doing pipelines is not that frithing. Thanks for taking the time to make this material
@szymonstepniak3 жыл бұрын
Thank you so much for your kind words! Take care, and have a good day!
@BE55Roberts3 жыл бұрын
Clear and concise explanation of variables within different contexts. Just what I was looking for!
@szymonstepniak3 жыл бұрын
I'm so happy to hear that, Bradley! Thanks for your kind words and have a good day!
@marwanalturky4 жыл бұрын
thank you for taking some time and teach people something very valuable.
@szymonstepniak4 жыл бұрын
Thank you so much for the kind words, Memis! I'm happy to hear you find this video valuable. Have a good day!
@shashankmarri10562 жыл бұрын
Lovely and brilliant video. Precise to the point. Please make more videos on other devops concepts like Chef and Ansible.
@szymonstepniak2 жыл бұрын
Thank you!
@safaricourse30234 жыл бұрын
You are awesome.I learnt a lot from this video. I would like to see more videos of yours and learn new things in Jenkins Pipeline.
@szymonstepniak4 жыл бұрын
Thanks for the kind words! I would recommend subscribing to my channel if you haven't already - more Jenkins Pipeline related content coming soon :)
@safaricourse30234 жыл бұрын
@@szymonstepniak Thank you, I have subscribed it :) I request if you could please make a video on Shared Pipeline Libraries.
@szymonstepniak4 жыл бұрын
I have it on my list already :) Thanks for helping me in shaping the content for the upcoming videos 👍
@narayan89k3 жыл бұрын
Awesome and perfect video to learn Jenkins environment variable concepts and various types of it. Author has very clearly explained how they can be set, referred and overridden in groovy and also how they can be used in shell block. Thank you very much for this video ... Szymon ....
@szymonstepniak3 жыл бұрын
Thank you for your kind words, Narayanan! Have a good day!
@cqyzsssyzm Жыл бұрын
Thank you very much for the explanation, it is so easy to make a mistake...
@szymonstepniak Жыл бұрын
Thanks for your kind words, Tycho! Take care, and have a good day!
@hitabratabhainsa17192 жыл бұрын
Best tutorial for Jenkins...
@szymonstepniak2 жыл бұрын
Thank you so much for your kind words! Take care, and have a good day!
@pandorasbox55764 жыл бұрын
Hey Szymon.. Amazing Explanation!! This is the best video I have come across today.
@szymonstepniak4 жыл бұрын
Thanks for the kind words! Is there anything in this topic you would like to hear more about? I would love to hear your opinion and create next videos to match your expectations much closely. Thanks in advance!
@nikhileshsaggere3 жыл бұрын
Excellent tutorial and explaination, please add more such lucid and informative videos. Practical examples on both sh and bat commands in the script block would be helpful.🙏🏻
@szymonstepniak3 жыл бұрын
Thank you for your kind words, Nikhilesh! Have a good day!
@prakashperam Жыл бұрын
This is super detailed. Thank you very much
@szymonstepniak Жыл бұрын
I'm happy to hear that, Prakash! Take care, and have a good day!
@1986smooth19864 жыл бұрын
Thank you for your efforts. This tutorial is amazing.
@szymonstepniak4 жыл бұрын
Thank you, Khuswant! I'm glad to hear it was useful to you.
@devnullskull2 жыл бұрын
I second this. By far the best Jenkins tutorial video I've seen. Already looking to see what other videos you've made as this one just clicked with me and I said "ah, someone who gets it, and works and explains in a way that is very relatable."
@too_bad3 жыл бұрын
Excellent video. Thank you!
@szymonstepniak3 жыл бұрын
Thank you so much for your kind words! Take care, and have a good day!
@charank78522 жыл бұрын
Hi Excellent tutorial and explaination.I learnt a lot from this video.
@szymonstepniak2 жыл бұрын
Glad it was helpful! Take care, and have a good day!
@aadyanaanayacooking78632 жыл бұрын
Thank you so much . I was breaking my head .❤️❤️❤️
@szymonstepniak2 жыл бұрын
You’re welcome 😊 Take care, and have a good day!
@vigneshs42194 жыл бұрын
Excellent . Need more videos👍
@szymonstepniak4 жыл бұрын
Thank you for your kind words, Vignesh! Have a good day!
@whogashaga3 жыл бұрын
Thanks for sharing this! It helps me a lot.
@szymonstepniak3 жыл бұрын
I'm so glad to hear that! Take care, and have a good day!
@dinkum3753 жыл бұрын
The best guide on Jenkins Env Variables I have seen so far. Can you please also guide how to pass environment variables to a python script (that I have checked out from SCM) in Jenkins?
@szymonstepniak3 жыл бұрын
Thanks for your kind words, Muhammad! I guess you can read such a variable inside your Python script using `os.environ.get(name)`, or you can simply pass the value of the variable as an argument for the Python script (e.g. sh "python script.py '${env.VAR_NAME}'" - just make sure you wrap the env variable value with the quotes, so it is treated as a single string.) Good luck, have a good day!
@KernelFault4 жыл бұрын
Thank you for your videos. They are very helpful.
@szymonstepniak4 жыл бұрын
Thanks for the kind words, Dave! I'm glad to hear you find them helpful. Have a good day!
@daianacv65364 жыл бұрын
Szymon, thank you!! It's really awesome your explanation!!
@szymonstepniak4 жыл бұрын
Thanks for your kind words, Daiana. Have a good day!
@no1sploit5293 жыл бұрын
Great video Man !!
@vaddisivakumar2 жыл бұрын
Great explanation 👌🏻
@szymonstepniak2 жыл бұрын
Thanks for your kind words! Take care, and have a good day!
@loudouncps21073 жыл бұрын
Excellent tutorial , very useful
@szymonstepniak3 жыл бұрын
I'm happy to hear you find it helpful. Take care, and have a good day!
@alea91409 ай бұрын
Highly informative. Could you do the same with Jenkins YAML pipelines?
@tyagisong2 жыл бұрын
Thanks for explaining my many doubts
@szymonstepniak2 жыл бұрын
Thanks for your kind words! Take care, and have a good day!
4 жыл бұрын
Your videos are great, I like every detail.
@szymonstepniak4 жыл бұрын
Thank you, Roberto! I'm happy to hear you like it 😎👍
@OurHappyWorld3 жыл бұрын
Nice Explanation with soothing music. Do you have any videos that explains complex scripted pipelines?
@szymonstepniak3 жыл бұрын
Hi Prasad, thanks for the comment. All Jenkins pipeline related videos are available in this playlist - kzbin.info/www/bejne/l3e1m6GVadOVY7M&ab_channel=SzymonStepniak You can take a look and check if it contains content you are looking for. Have a good day!
@elangovans3104 жыл бұрын
Previously I had written in a scripted pipeline. After watching your tutorial I have understood the use of the declarative pipeline and now I am very interested in working on this. Thanks, @Szymon Stepniak
@szymonstepniak4 жыл бұрын
Thank you for your kind words, Elangovan! If you are interested in the declarative pipeline and scripted pipeline differences, I made a video about it some time ago - kzbin.info/www/bejne/e5rCf55nadulq6c Thanks again, and have a good day!
@WaldiShrek2 жыл бұрын
Very good tutorial. But how inject a global environment variable so it can be used also by different build jobs? E.g. for locking other builds while a special build is running
@szymonstepniak2 жыл бұрын
You can't define environment variable that goes beyond the context of the current job/build. I'm guessing that you are looking for something like lockable resources - www.jenkins.io/doc/pipeline/steps/lockable-resources/ This thing allows you to lock specific "resource", and if there is concurrent job running that also tries to acquire the same lock, it will have to wait until the other job releases it. Hope it helps!
@dmitriyengineer24412 жыл бұрын
Yo man your explanation is so good. Come on guys, 2 more likes for 1k😁
@szymonstepniak2 жыл бұрын
Thanks, Dmitriy! :) Take care, and have a good day!
@ashok.97614 жыл бұрын
Well explained sir ... Easy to understand .. Can you make it one video dockerfile
@szymonstepniak4 жыл бұрын
Hi! Thanks for the kind words. Regarding Dockerfile video - is there anything specific that interests you most? I added this topic to my backlog, but it would be very helpful if you could share some more thoughts. Thanks in advance, and have a nice day!
@chintalapativenkataramarahul3 жыл бұрын
Can you please explain the difference between src and vars folders? Which one to use in which case and why?
@andreymelnichenko93734 жыл бұрын
amazing video! Thanks a lot! This is exactly what I looking for!
@szymonstepniak4 жыл бұрын
Thank you for your kind words, Andrey! I'm glad to hear you've found exactly what you were looking for. Have a good day!
@andreymelnichenko93734 жыл бұрын
@@szymonstepniak Also, would be grate to get tutorial about multibranch pipeline project based on git hook trigger, and AWS integration. For me, as automation engineer it is actual question cause on my project I need create test infrastructure without DevOps specialist.
@szymonstepniak4 жыл бұрын
@@andreymelnichenko9373 Thanks for suggesting the topic. I plan to create a full video dedicated to creating a complete CI/CD pipeline for a Java project, probably with some AWS parts as well. What type of integration with AWS are you interested in most? I could put it to that video if it fits the general idea. Thanks in advance, and have a good day!
@Walruz10002 жыл бұрын
Thanks, very helpful content. I have recently started working with Jenkins again after 2 years using only code build and code pipeline and these videos are really helping me get back up to speed quickly.
@szymonstepniak2 жыл бұрын
Thanks for your kind words! And good luck with your Jenkins experience! :)
@dumpalpr4 жыл бұрын
Very informative video sir as always. Would it be possible to make a video which cover below topics. 1) Full end to end pipe line with any sample application which depict a real time implementation. Different states involves Builds maintenance Reporting ..etc 2) Typical Jenkins environment set-up in real production world. Kind of architectural representation. Thank you again.
@szymonstepniak4 жыл бұрын
Hi, Pradeep! Thank you very much for the comment and topics suggestion. I'm going to create a video on setting up the full CICD pipeline for Java projects, and maybe Node.js projects as well in the future. As for the production-ready Jenkins infrastructure, I have something like this on the backlog already - added your comment as well. Thanks a lot for the suggestions! I will do my best to publish the videos you suggested as soon as possible. Have a good day!
@dumpalpr4 жыл бұрын
@@szymonstepniak Thank you for considering my input. Also can you please shed some light around best practices in managing CI/CD in a typical agile projects, Like how you create or maintain build definitions for different environment. Regards, Pradeep
@szymonstepniak4 жыл бұрын
@@dumpalpr Yeah, I think the full CI/CD pipeline example for an exemplary Java project will show a few best practices. It's hard to explain them without a specific context. Thanks again for the insightful comment, have a good day!
@jinkahari3 жыл бұрын
Thanks for your video stepniak. How to write the script to delete the workspace using environment variable like boolean?
@Jonathanmismamente4 жыл бұрын
This is awesome and useful video!! Thanks you!
@szymonstepniak4 жыл бұрын
Thanks for the comment, Jonathan! 👍 I'm happy to hear you find it useful 😀
@danvyr4 жыл бұрын
Great explanation!
@szymonstepniak4 жыл бұрын
Thanks for the comment, Vitali! 👍 It helps ranking video higher, and that means a lot to me. I'm happy to hear you find the video useful. I hope you will find other videos useful as well 🙂
@pavangummadi33784 жыл бұрын
Hi Szymon Stepniak tutorial is amazing, can you please tell me about the green demo console which you are using to test pipeline? is it blue ocean?
@szymonstepniak4 жыл бұрын
Hi Pavan! Thanks for the comment 🙏 That's correct, this is Blue Ocean UI.
@CarlosManuel-qf7mb3 жыл бұрын
excellent video. I was looking but I couldn't find how to use the user running the pipeline and save it in an environment variable. is that possible without using Jenkins plugins?
@szymonstepniak3 жыл бұрын
You can use Build User Vars plugin to access such information through environment variables - plugins.jenkins.io/build-user-vars-plugin/ The documentation page contains pipeline example, you need to use the "wrap" block to make those variables exposed. Good luck and have a good day!
@srinivasgowda93353 жыл бұрын
@Szymon Stepniak thanks for your wonderful video. I had one question. Say suppose i have declared a global environment variable which is empty or null. environment { a= "" } This will be overwritten in next stages and i am able to get those. steps{ script { a= 'b' } } a= b am able to get this. But i am failing to get that environment variable in the post step of extended email. its always printing null value. is there a way i can read that modified value? post{ always{ $a } } a value is null or empty. how do i get the modified value? ie a = b
@szymonstepniak3 жыл бұрын
Hi Srinivas! It won't work as you expect as far as I remember. In your example, you don't override the env variable in the script block, but you create a local variable `a` inside the script block. The environment variable once initialized inside the "environment" block cannot be overridden (with a few exceptions like overriding env variable in the withEnv block for a limited scope.) Check out my blog post for more detailed information - e.printstacktrace.blog/jenkins-pipeline-environment-variables-the-definitive-guide/#overriding-environment-variables The one workaround I could suggest you to do it to skip initializing this variable in the environment block and creating this variable inside the script block. In this case, Jenkins pipeline will allow you to override such a variable. I explain this example in my blog post as well. Good luck and have a good day!
@srinivasgowda93353 жыл бұрын
@@szymonstepniak Thanks so much for your prompt response. Yes before posting i had seen that blog thank you. One more thing i wanted to ask and get re-confirmed Question--> is there a way to export envars to a file like this Jenkins-url/lastSuccessfulBuild/injectedEnvVars/export/file.txt same in pipeline jobs? i am able to do in freestyle jobs, just wanted to check whether we can do same in pipeline jobs. Many blogs i read but i found that answer is no. Is this true? or do you have any suggestion on this?
@szymonstepniak3 жыл бұрын
@@srinivasgowda9335 I have no suggestion in this area, I've never done anything like that in any of my pipelines. I would look into issues.jenkins.io/browse/JENKINS-42614 and ask a question there if the workaround posted in the comments does not work as expected. Good luck!
@srinivasgowda93353 жыл бұрын
@@szymonstepniak Thank you so much :)
@pavelow363 жыл бұрын
I'm currently struggling with a Jenkins pipeline using the Extended Choice plugin and adding it into the Jenkins script. I am unable to correctly create a pipeline script using pure declarative script. But I am able to do it if I go through the UI. Thank you.
@szymonstepniak3 жыл бұрын
Hi there! Do you have any specific question related to the Jenkins pipeline environment variables? Have a good day!
@pavelow363 жыл бұрын
@@szymonstepniak I think I'm getting it now. Variables are just not behaving correctly during expansion. For example, the Extended Choice parameters selected will create a comma delimited list of strings like Cars="ford,toyota,jaguar", but when I do like, sh '''echo ${Cars} | sed "s/,/_/g" ''' to replace all the commas with underscores it does not do it. Thanks Szymon!
@szymonstepniak3 жыл бұрын
@@pavelow36 Every env variable is represented as a string, so if you end up storing a list of elements, it will be represented as a string value. If you use the "sh" step, make sure you set "returnStdout: true" as explained in the blog post e.printstacktrace.blog/jenkins-pipeline-environment-variables-the-definitive-guide/. Alternatively, you can make the replacement inside the script block and using Groovy code like Cars.replaceAll(",", "_"). Good luck!
@pavelow363 жыл бұрын
@@szymonstepniak Thank you! will try from my end. Please continue to teach. You are a good teacher.
@dipi4112 жыл бұрын
it's very informative
@szymonstepniak2 жыл бұрын
Glad to hear that, Bhabani! Take care, and have a good day!
@АлексейЗорин-й9с3 жыл бұрын
Hi. Great video. I was looking for an answer on how to set up a pipeline in jenkins and came across your video. It is very interesting and understandable. But I still couldn't solve my problem. Can I ask you for help? At first glance, the task is simple. But I cannot find the answers on the net for it. If I can ask you for help, it would be great)
@szymonstepniak3 жыл бұрын
Hi Алексей, what is the problem you faced with the pipeline? Is it related to Jenkins environment variables? Have a good day!
@katejermina4 жыл бұрын
Very helpful explanation. Thank you Is there a way to stash a variable onto another stage (that uses another agent)?
@szymonstepniak4 жыл бұрын
Thanks, Ali! Env variables are agent-agnostic, which means that you can set a variable in a stage that gets executed on agent A, and then access this env variable in the next stage that gets executed by agent B. Stash/unstash operations are used with files.
@katejermina4 жыл бұрын
@@szymonstepniakAhhh I see. Thanks again!
@vishweshshouche26982 жыл бұрын
Hello Szymon - Small question and maybe dumb, how do we get Jenkins UI like you, I have blue ocean plug-ins installed on my laptop as well but did not get able to do get UI like you.
@szymonstepniak2 жыл бұрын
Hi Vihwesh! This is Blue Ocean UI plugin. Take care, and have a good day!
@vishweshshouche26982 жыл бұрын
@@szymonstepniak thank you
@ScrolltheNature3 жыл бұрын
You make me understand this, do you have autocompletion/linter available for dsl pipelines in any editors which you prefer.
@pablov.santos46894 жыл бұрын
very good, thanks man!!!
@szymonstepniak4 жыл бұрын
Thanks for the kind words, Pablo! I'm happy to hear you find it useful :)
@Oswee4 жыл бұрын
Personally i am more interested in interpolation/substitution part of the shell in the Jenkinsfiles. Specifically when i need to have double quotes, slashes, etc in the shell commands.
@szymonstepniak3 жыл бұрын
Thanks for the feedback, Dzintars! I'm thinking about creating a video that explains Groovy from the Jenkins pipeline syntax perspective and explains how to avoid common pitfalls, including escaping slashes in strings. Stay tuned! :)
@Oswee3 жыл бұрын
@@szymonstepniak Tnx. That would be great! In the wild i saw it's quite common question.
@szymonstepniak3 жыл бұрын
@@Oswee Absolutely, I do agree! I see many people treat Jenkins pipeline Groovy syntax as it was a vanila Groovy code which in many cases causes some issues. Hope I will be able to help in this area as well :) Thanks and have a good day!
@harishkashyapm4 жыл бұрын
Hello Szymon, is it possible to add parallel steps in a pipeline? Each parallel step to run when an environment Boolean parameter is set to true.
@szymonstepniak4 жыл бұрын
Hi Harish! Could you elaborate, please? Correct me if I didn't understand your question correctly, but the answer is - yes. You can use the "when" block (www.jenkins.io/doc/book/pipeline/syntax/#when) inside the "stage" block, no matter if the stage gets executed sequentially or in the parallel. You can use the "when" block either to all parallel stages or you can define separate block for each parallel stage. Let me know if you have run into some specific issue. Will do my best to help you. Have a good day!
@harishkashyapm4 жыл бұрын
@@szymonstepniak Thanks for the reply, Szymon. I have a Boolean parameter to accept input via a checkbox. I have a set of set of such checkboxes. Each checkbox stands for an environment. If the checkbox is checked, then I would like to deploy code to that environment. Also, I would like to deploy to all the environments in parallel. If you have any suggestions for me to implement this, I world be really grateful.
@szymonstepniak4 жыл бұрын
@@harishkashyapm You could use either matrix feature (I made a video about it in a bit different context - kzbin.info/www/bejne/oGLPeWashM2omdk) or the declarative parallel configuration. Here is a simple example of using matrix alongside with the boolean checkbox parameters - gist.github.com/wololock/7c747d09e5e75bee8518143e8174a647 And here is a simple example of using declarative parallel stages alongside with the boolean checkbox parameters - gist.github.com/wololock/9e9e0abc55858a735e00c5c9b6e54fe8 Each of them has its pros and cons. The matrix is better if you want to follow the DRY rule (don't repeat yourself) - you just define axes and a single stage. The only problem with this approach is that it does not produce clean UI and you need to hover at the axis to check what environment it is. (You can't use the axis variable in the stage name unfortunately.) On the other hand, the second approach produces much cleaner and simpler UI, but it requires some repetition. I would choose whatever works for you better. I hope it helps.
@cptechno3 жыл бұрын
I'm using Jenkins free version. I don't see the screens that you are using in this demo. Can you explain your environment for Jenkins.
@szymonstepniak3 жыл бұрын
Hi there! The GUI you can see in the video is provided by the Blue Ocean UI plugin. You can install it from the Jenkins Plugin Manager. Good luck, and have a good day!
@yusufzainee3 жыл бұрын
@snymon Stepniak, I have a problem. Im trying to edit the Path env variable, where in, in the pipeline script, i can see the changed env value, but when the call lands to a java step class and i try to system.getenv("PATH"), i dont get the edited value. Why is that so and how can i overcome this problem?
@szymonstepniak3 жыл бұрын
Hi Yusuf! I don't know how you update the PATH env variable, but I'm guessing that you do it using "sh" (or "bat") step. If this is the case, then the updated variable does not get exposed to the global env variables, but gets updated only inside the "sh" script process. You can overcome this limitation by using e.g. withEnv() directive. You can find an example in my blog post: e.printstacktrace.blog/jenkins-pipeline-environment-variables-the-definitive-guide/#setting-environment-variables Hope it helps. Have a good day!
@pedadatuber2 жыл бұрын
Would be great to know how withEnv is implemented, could you share a pointer to the source code?
@szymonstepniak2 жыл бұрын
Hi Peter, here's the source code github.com/jenkinsci/workflow-basic-steps-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java and the associated unit test github.com/jenkinsci/workflow-basic-steps-plugin/blob/master/src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepTest.java
@pedadatuber2 жыл бұрын
@@szymonstepniak thanks a lot!
@siddharthmehra81783 жыл бұрын
Hello Szymon, Thanks for awesome explanation. I have a question, I want to fetch the tags from the git repo and store it in a variable. How can I do that? Below is what I'm doing right now. environment{ GIT_TAG = sh(returnStdout: true, script: "git tag --sort version:refname | grep -i pcc*| tail -1") } Error that I'm getting: + git tag --sort version:refname + grep -i pcc* fatal: Not a git repository (or any parent up to mount point /var/jenkins_home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). + tail -1 [Pipeline] withEnv [Pipeline] { [Pipeline] echo The lastest tag is : null
@ScrolltheNature3 жыл бұрын
Thanks, but when i am printing env i am not getting branch name variable & git commit variable although my repo is on gitlab, also i need to get the commit message to select the execution accordingly. currently i am using gitlab api curl to get these values in pipelines.let me know if you any thoughts on this.
@szymonstepniak3 жыл бұрын
Hmm, I never used Gitlab with Jenkins, so I have no out-of-the-box solution to this problem. I would suggest checking if there is a gitlab plugin for Jenkins and maybe it is required to install it to get those variables exposed correctly. Or maybe it's not yet supported and there is a corresponding JIRA issue you may find in your research. Good luck and have a good day!
@guvvalamadhav49034 жыл бұрын
This video helped me a lot sir, Is there any way to contact you personally sir ?
@szymonstepniak4 жыл бұрын
I'm glad to hear you found this video helpful. Regarding your question, my contact email is mentioned in the video description and in the channel information page. Have a good day!
@guvvalamadhav49034 жыл бұрын
@@szymonstepniak Thanks for the reply sir
@SebastianPlagge4 жыл бұрын
Your video is awesome (and nice music in the background). Started teaching myself this stuff but I still make many mistakes :(. Right now I have a problem with an environmental variable "CHANGE_TARGET". When my team creates a Pull Request, Jenkins automatically gets notified and starts the pipeline. However, for several reasons, I want to run a specific step just, if the CHANGE_TARGET is /^release\/\d{2}\.\d{1,2}$/ (e.g. release/20.6). This works so far, but when there is no Pull Request there is no CHANGE_TARGET and I get the error No such property CHANGE_TARGET for class: groovy.lang.Binding. I know what's the problem but I do not know a good way, to deal with it so far. I want a when condition, that if the change target is correct, pipeline should run this stage... But so far I just go from error to error :( Do you have an idea?
@SebastianPlagge4 жыл бұрын
By the way. I just realised, that the Groovy Regular Expression Guide and Jenkins Pipeline Environment Guides are by you. I used them a lot the last months. Thank you so much! It was super helpful!
@szymonstepniak4 жыл бұрын
Hi, Sebastian! Thanks for your kind words! I'm happy to hear both video and blog posts were useful to you 🙂 Regarding your question, I would try using "changeRequest" to define your expected conditions. Take a look at this simple example - gist.github.com/wololock/508e1220ecb950d6574d07af12e35375 Here I define a following condition for the "Test" stage: execute when the pull request to "develop" is created and when it comes from the branch like TEST-123. You don't have to specify both "target" and "branch", you can use just a single one. Or even you can use a condition like "changeRequest()" without any additional options - in this case, the condition is true to any pull request. I hope it helps you solve the problem. Happy coding!
@SebastianPlagge4 жыл бұрын
@@szymonstepniak Thank you very much. Your example was very helpful. It took me a while to get the REGEXP right but now it works. It also took me a while to understand that "branch" (at least in my case) was the change target and not the branch name. I am still pretty unsure when to use single / double quotes. When to use echo and when to use sh. Everything works but I think I can improve my pipeline a lot. :D
@szymonstepniak4 жыл бұрын
@@SebastianPlagge Yes, I should also post this link to give you more information about "changeRequest" condition type - jenkins.io/doc/book/pipeline/syntax/#when All its options refer to CHANGE_* variables, so "branch" in this case means CHANGE_BRANCH. When it comes to regular expression, it is much easier to use Groovy's backslash string feature, so you don't have to worry about escaping characters. I used "echo" and "sh" steps in this video just to illustrate how env variables can be used in both cases. It should not be confusing when to use one or another. When you want to print something to the console, use the "echo" step. When you need to execute some shell command or script, the "sh" step (for Linux nodes) is your best choice. Keep practicing and learning, the time for improvements will come :) I can tell you that I develop a Jenkins shared library that produces pipelines for engineers in the company I work for, and it's been 2 years now and we still learn new things and try to improve what does not work as expected. Just be patient and let your Jenkinsfile do its job :) Good luck!
@SebastianPlagge4 жыл бұрын
@@szymonstepniak thanks, I had the information but I read too fast and did not see it. I really need to practice more and I will do some exercises with Groovy's backslash feature. End of December we still used SVN + Hudson. I was working over Christmas and spontanously started to migrate SVN to GIT and Hudson to Jenkins. Since we have around 40 repos and complex ANT scripts for versioning I had a lot to do and learn. Since the devs of my team are pretty lazy I started to put a lot of stuff in our pipelines. It takes care about giving the correct version, it creates tags and pushes everything to git, it checks if branches are named correctly. One thing I want to do are shared libraries (I read a bit about it but had no time so far). Right now it is so much work to fix bugs. I need to update all repos and all branches (at least the current release branch). It is annoying and takes a lot of time. Future goals are sonarqube / quality gates. Everything works fine but I think there is a lot of room for improvement ;)
@sirdomino1000 Жыл бұрын
Hello do you provide training ?
@szymonstepniak Жыл бұрын
No, I dont. Take care, and have a good day!
@theentertainmentetc642 жыл бұрын
Hi , Your knowledge sharing is awesome , need some help on the below task Need to generate a test cases TestNGXML report and need to push to XRAY using restapi ... All these things should be done by pipeline and shell script .. can you give me some documentation as i am not getting proper knowledge from xray official website
@szymonstepniak2 жыл бұрын
Hi! There's nothing I could point you directly to that comes to my mind. I have no experience with the tools you mentioned in the comment. Good luck, and have a good day!
@jafarshaik51602 жыл бұрын
Hello stepniak sir do u have any course on Jenkins scripting in udemy please
@szymonstepniak2 жыл бұрын
Nope, I have no courses on Udemy.
@cacheman2k3 жыл бұрын
Thanks!
@szymonstepniak3 жыл бұрын
Welcome!
@chetankashetty64093 жыл бұрын
How do we disable a Jenkins job (Disable Project option) with Jenkinsfile? Thanks
@GaadhiMahendra3 жыл бұрын
Thank you
@szymonstepniak3 жыл бұрын
Thanks! :)
@lemonUA4 жыл бұрын
Is there a way to trigger Jenkins Job from Slack with different parameters and variables? Can't understand how to use /build parameter1 command in Slack :'(
@szymonstepniak4 жыл бұрын
I have no answer to your question. I never tried configuring Slack to trigger Jenkins jobs. Try looking at the Slack plugin documentation and check if there is any form of contact with its maintainers. I wish I could help you more. Good luck and have a good day! 👍
@beniamintucu25882 жыл бұрын
How can I activate a virtual environment variable that I have on my system, and use it to call a python scrypt in a stage ?
@narendrabhupathiraju89863 жыл бұрын
hi, how can i auto approval notification to mail in jenkins pipeline?
@szymonstepniak3 жыл бұрын
Hi Narendra, I have no answer to your question. Good luck, and have a good day!
@ramaraokondeti71574 жыл бұрын
Nice explanation Szymon Great work :) In declarative pipeline when one stage fails it will fail all next stages in the entire pipeline right, Can you tell me how to go next stage(or Continue the pipeline) if any previous stage fails ? and my second question is may I know how to move one stage to another stage? for example stage("Clean") { steps { sh """ rm -rf /home/.cache """ post { always{ node ( 'linux' ) { sendnotifications currentBuild.result, 'mm.com' } } from the above example I want to move clean stage into post may I know how to do ? Thanks in advance
@szymonstepniak4 жыл бұрын
Hey, Ramarao! Thanks for one more comment ☺️ I really appreciate that. Regarding your question - check this post from my blog e.printstacktrace.blog/how-to-time-out-jenkins-pipeline-stage-and-keep-the-pipeline-running/ It explains how to handle the timeout and keep running the pipeline. It's not exactly the same thing you are asking, but the timeout is just an error in terms of the pipeline, so it should give you a good understanding of how to use the same mechanism to implement your expected solution. Let me know if it worked for you. Thanks in advance!
@ramaraokondeti71574 жыл бұрын
@@szymonstepniak Thanks for sharing the link looks like in my scenario try catch will work, So that if stage fails it will print the message from the catch method and will go to next stage. Correct me if I am wrong.
@szymonstepniak4 жыл бұрын
@@ramaraokondeti7157 That is correct. In addition to that, you can use "catchError" step to mark the failing stage as "UNSTABLE". But it depends on your use case. If printing a message to console and keeping the stage "STABLE" is OK, then using try-catch is all you need. Good luck!
@mahendrapalla13733 жыл бұрын
Hi Brother, Thanks for the video. I was having 2 scenarios. 1) how to run few stages in one Node and another few Stages in another NODE 2) how to deploy in 100 servers Parallelly with Jenkins. It would be greatful if u Post a video or explan me. Thanks , b Safe
@szymonstepniak3 жыл бұрын
Hi Mahendra! I don't have any out-of-the box answer to you. I may, however, post a video in the future that covers some similar aspects, but I can't promise anything. Take care, and have a good day!
@R-Kannada-DevOps3 жыл бұрын
I need to pass my build number to my Kubernetes manifest file dynamically , in jenkins pipeline, how can do this step, i need to use this step for building dockoer image with buildnumber and pass the same build number to my manifest which is my scm
@R-Kannada-DevOps2 жыл бұрын
I found a solution for this and Thank for your effort
@cptechno3 жыл бұрын
You forget to explore two questions: 1) Are environment variables passed to execution agents? Demo? 2) Are environment variables passed when calling another pipeline job.
@szymonstepniak3 жыл бұрын
I must admit I haven't think about those two cases when I was preparing the material for that video. The answers are: 1) Yes, they are passed. I guess the only exception is the env var defined in the script block. 2) Nope. When you trigger another job from the pipeline, it has no access to the env variables you set in the pipeline. Thanks for the comment, have a good day!
@satdanie73493 жыл бұрын
How to learn Jenkinsfile from scratch?
@szymonstepniak3 жыл бұрын
I can recommend checking @TechWorldwithNana KZbin channel and her Complete Jenkins Pipeline Tutorial video - kzbin.info/www/bejne/bXymhGpmqKiigZI Good luck and have fun!
@daherdaher25602 жыл бұрын
Genius
@evhen_ Жыл бұрын
OMG!!!
@szymonstepniak11 ай бұрын
Thanks for the comment! Take care, and have a good day!