{"id":138,"date":"2023-09-16T14:46:38","date_gmt":"2023-09-16T11:46:38","guid":{"rendered":"https:\/\/codeblog.xyz\/?p=138"},"modified":"2023-10-23T01:48:59","modified_gmt":"2023-10-22T22:48:59","slug":"setup-azure-devopssetup-pipeline-with-selfhosted-agent","status":"publish","type":"post","link":"https:\/\/codeblog.xyz\/?p=138","title":{"rendered":"SetUp Azure DevOpsSetUp pipeline with selfhosted agent"},"content":{"rendered":"\n<p>Running a pipeline using Azure DevOps involves several steps, including creating a YAML file to define your pipeline and setting up a self-hosted agent for execution. Let&#8217;s dive deep into each of these aspects with detailed explanations and examples.<\/p>\n\n\n\n<p><strong>Creating a YAML Pipeline:<\/strong><\/p>\n\n\n\n<p>Azure DevOps provides a powerful feature called YAML Pipelines, which allows you to define your build and release pipelines as code. Here&#8217;s a step-by-step guide to creating a YAML pipeline:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Sign in to Azure DevOps:<\/strong><br>Make sure you&#8217;re logged into your Azure DevOps account.<\/li>\n\n\n\n<li><strong>Navigate to Pipelines:<\/strong><br>Go to the &#8220;Pipelines&#8221; section in your Azure DevOps project.<\/li>\n\n\n\n<li><strong>Create New Pipeline:<\/strong><br>Click on the &#8220;New Pipeline&#8221; button. This will initiate the pipeline creation process.<\/li>\n\n\n\n<li><strong>Select Repository:<\/strong><br>Choose the repository where your application code is stored.<\/li>\n\n\n\n<li><strong>Configure Pipeline:<\/strong><br>Select &#8220;YAML&#8221; as the pipeline configuration type.<\/li>\n\n\n\n<li><strong>Create YAML File:<\/strong><br>You&#8217;ll need to create a YAML file named <code>azure-pipeline.yml<\/code> (or any name you prefer) in the root of your repository. This file will define your pipeline&#8217;s stages, jobs, and tasks.<\/li>\n\n\n\n<li><strong>Define Pipeline:<\/strong><br>In your YAML file, define your pipeline using YAML syntax. Here&#8217;s an example:<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;yaml&quot;,&quot;mime&quot;:&quot;text\/x-yaml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;YAML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;yaml&quot;}\">trigger:\n- main  # Trigger pipeline on changes to the main branch\n\npool:\n  vmImage: 'ubuntu-latest'  # Specify the VM image for the pipeline agent\n\njobs:\n- job: Build\n  steps:\n  - script: echo 'Building the application...'\n    displayName: 'Build Application'\n\n- job: Test\n  steps:\n  - script: echo 'Running tests...'\n    displayName: 'Run Tests'<\/pre><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"8\">\n<li><strong>Commit and Push:<\/strong><br>Once you&#8217;ve defined your YAML file, commit and push it to your repository.<\/li>\n\n\n\n<li><strong>Trigger Pipeline:<\/strong><br>After the commit, Azure DevOps will automatically detect the new YAML pipeline definition and trigger the pipeline according to the specified conditions.<\/li>\n<\/ol>\n\n\n\n<p><strong>Creating a Self-Hosted Agent:<\/strong><\/p>\n\n\n\n<p>A self-hosted agent is a machine within your environment that runs pipeline jobs. This allows you to execute pipelines on your own infrastructure. Here&#8217;s how to set up a self-hosted agent:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Install Dependencies:<\/strong><br>On the machine you intend to use as a self-hosted agent, ensure you have the necessary software installed, such as Git, Node.js (for Angular), .NET Core (for C# .NET), and SQL Server.<\/li>\n\n\n\n<li><strong>Download Agent Package:<\/strong><br>In Azure DevOps, go to your project settings, navigate to &#8220;Agent Pools,&#8221; and click &#8220;New agent.&#8221; Follow the instructions to download the agent package for your operating system.<\/li>\n\n\n\n<li><strong>Configure Agent:<\/strong><br>Extract the downloaded package and run the configuration script. During configuration, provide your Azure DevOps account details and choose an agent pool.<\/li>\n\n\n\n<li><strong>Run Agent:<\/strong><br>Start the agent service using the provided script. This will register the agent with your Azure DevOps project.<\/li>\n\n\n\n<li><strong>Assign Agent to Jobs:<\/strong><br>In your YAML pipeline, you can specify that certain jobs should run on your self-hosted agent using the <code>pool<\/code> keyword.<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;yaml&quot;,&quot;mime&quot;:&quot;text\/x-yaml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;YAML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;yaml&quot;}\">jobs:\n- job: Build\n  pool:\n    name: MySelfHostedAgent  # Name of your self-hosted agent pool\n  steps:\n  - script: echo 'Building the application...'\n    displayName: 'Build Application'<\/pre><\/div>\n\n\n\n<p>By following these steps, you&#8217;ll be able to create a YAML pipeline and set up a self-hosted agent for executing your pipeline jobs. This approach empowers you to manage your entire CI\/CD process as code and leverage your own infrastructure for execution.<\/p>\n\n\n\n<p>Remember, the examples provided are simplified for illustration purposes. Depending on your project&#8217;s complexity, you may need to include more detailed steps, environment configurations, and error handling in your YAML pipeline definition.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Running a pipeline using Azure DevOps involves several steps, including creating a YAML file to define your pipeline and setting up a self-hosted agent for execution. Let&#8217;s dive deep into each of these aspects with detailed explanations and examples. Creating a YAML Pipeline: Azure DevOps provides a powerful feature called YAML Pipelines, which allows you [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":178,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/codeblog.xyz\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeblog.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeblog.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeblog.xyz\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codeblog.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":1,"href":"https:\/\/codeblog.xyz\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":139,"href":"https:\/\/codeblog.xyz\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions\/139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeblog.xyz\/index.php?rest_route=\/wp\/v2\/media\/178"}],"wp:attachment":[{"href":"https:\/\/codeblog.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeblog.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeblog.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}