0

I need this scenario to be accomplish Jenkins is the main ci/cd tool now we want to use Azure to be our build server but only for the build that is:

  1. Jenkins checkout source
  2. Run some build-in scripts to prepare for build
  3. Send source which previously check out to the build server <-- this is where the AZURE part steps in
  4. Copy the created artifacts back to Jenkins slave
  5. Continue with CD on Jenkins slave

How do i combine the section 3 ?

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
user63898
  • 29,839
  • 85
  • 272
  • 514
  • maybe it can helps https://learn.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops#artifact-sources---jenkins – Shayki Abramczyk Aug 31 '20 at 11:16

1 Answers1

0

How do i combine the section 3 ?

As far as I know, you can use Azure Devops self-hosted agent to connect azure devops and Jenkins.

You can refer to the following steps:

  1. Create an Azure Devops Self-hosted agent on the Jenkins server.

  2. Since the Checkout Step is on Jenkins, you could add Copy file task in Azure Devops to copy the Source to the Build Directory.

e.g. Source Repo Path -> $(Build.SourcesDirectory)

enter image description here

  1. After the build step, you can copy the files back to the jenkins slave path.

e.g. Source: $(build.artifactstagingdirectory) -> Target: Slave Path

If your need to copy file to another remote machine, you could try to use Copy files over SSH or Windows Machine File Copy task.

Update:

After you configure the source, you could publish the repo as artifacts in Jenkins Server.

You could use the Jenkins download artifacts task in azure devops to download the artifacts.

Note: The artifacts will be downloaded to $(Build.ArtifactStagingDirectory).

Then you could run the task and publish the build artifacts on Hosted Macos Agent.

To Copy the created artifacts back to Jenkins:

You could add another Agent job and use the self-hosted agent(On linux AWS) to download the artifacts to jenkins server.

Agent Job 1 is running on Hosted MacOs agent. Agent Job 2 is ruuning on Self-hosted agent.

Update2:

Yaml Sample:

stages:
- stage: CopyFile
  pool:
   name: default
  jobs:
    - job: testjob
      steps:
      - task: CopyFiles@2
        inputs:
          SourceFolder: 'Local Path'
          Contents: '**'
          TargetFolder: '$(build.artifactstagingdirectory)'
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)'
          ArtifactName: 'Source'
          publishLocation: 'Container'

- stage: BuildProject
  dependsOn: CopyFile
  pool:
    vmImage: ubuntu-16.04
  jobs:
    - job: buildjob
      steps:
      - task: DownloadBuildArtifacts@0
        inputs:
          buildType: 'current'
          downloadType: 'single'
          artifactName: 'Source'
          downloadPath: '$(System.ArtifactsDirectory)'
      - task: xxx(build task)
       

      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)'
          ArtifactName: 'Artifacts'
          publishLocation: 'Container'
      
      

- stage: BackToJenkins
  dependsOn: BuildProject
  pool:
   name: default
  jobs:
    - job: Sendjob
      steps:
      - task: DownloadBuildArtifacts@0
        inputs:
          buildType: 'current'
          downloadType: 'single'
          artifactName: 'Artifacts'
          downloadPath: '$(System.ArtifactsDirectory)'

You need to modify the path(Publish Path, Download Path) to meet your needs.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Thanks for the info, but for self-hosted agent i need mac machine which i do not have . this is the main problem ! i need mac machine or VM – user63898 Sep 01 '20 at 05:03
  • Where is your jenkins server? If you jenkins is on local machine, you could create self-hosted agent. Could you please explain the main problem ("i need mac machine or VM")? Thanks for your time. – Kevin Lu-MSFT Sep 01 '20 at 05:22
  • 1
    my Jenkins server is on Linux AWS machine, i need to simple need to be able to build mac ios app for this i need mac server , all source code and configuration manipulation are done on the Jenkins server i want to pass the code to the mac build server and when it is done to get back the compiled "ipa" from it – user63898 Sep 01 '20 at 05:34
  • Thanks for your explaination. I could understand your requirement. I have updated the answer. Please check if it could give you some help. – Kevin Lu-MSFT Sep 01 '20 at 06:06
  • thanks for answer but still i have problem and i explain, I'm checking out from more than 1 repo (in fact 3 ) in the Jenkins server, then i do manipulations on the files and then i need to trigger the build on the files .. i don't have a stage where i publish the files to repo . so i do not have the stage ( as you wrote ) of : "you could publish the repo as artifacts in Jenkins Server." can't i just copy them to the build server in another way ? – user63898 Sep 01 '20 at 06:41
  • The other way is that you can add one agent job before the Macos Build Job(self-hosted agent), copy and publish all repos as azure devops build artifacts . Then you could download the build artifacts in Macos Agent Job and build it. Finally, you could download the Macos Agent Job Artifacts back to Jenkins Server. This method does not require publishing artifacts in jenkins. – Kevin Lu-MSFT Sep 01 '20 at 06:59
  • Since the local source repo cannot be directly delivered to the Microsft-hosted agent, we need to use artifacts to deliver it. Besides, I may not be able to think of a better way. Sorry. – Kevin Lu-MSFT Sep 01 '20 at 07:00
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220775/discussion-between-user63898-and-kevin-lu-msft). – user63898 Sep 01 '20 at 07:27
  • i did all what you pointed out , installed the agent in jenkins , also i can see the agent in the Azure devops dashboard and it is online , my missing part is how do i connect the self-hosted agent with the hosted agent ? so it will be triggered from the self hosted and copy the files and compile on the hosted – user63898 Sep 01 '20 at 12:36
  • You could use Azure Devops Build artifacts to connect the self-hosted agent and hosted macos agent. You also need to set the `Dependencies` for each agent job. – Kevin Lu-MSFT Sep 02 '20 at 01:02
  • Thanks i will check Azure Devops Build artifacts, how do i trigger the build from the self -hosted jenkins server and not the hosted mac? – user63898 Sep 02 '20 at 04:49
  • Do you mean that you need to trigger the build from Jenkins server? If so, you could use Powershell to run the [Rest API](https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.0) in Jenkins Server to trigger it. – Kevin Lu-MSFT Sep 02 '20 at 09:42
  • how can i call back Jenkins when azure agent pipeline job is done? – user63898 Sep 03 '20 at 11:41
  • In the third agent job, you may try to add the `Jenkins queue job` task to call back Jenkins. Please check if it could work. Thank you for your hard work, I hope you can achieve your purpose. – Kevin Lu-MSFT Sep 04 '20 at 01:20
  • i will try , can you please check this another question ? https://stackoverflow.com/questions/63726523/azure-devops-pipeline-restapi-how-to-pass-varible-with-sourcefolder-for-copyfile – user63898 Sep 04 '20 at 07:01